title: SqlException: Cannot insert explicit value for identity column in table 'Tasks' when IDENTITY_INSERT is set to OFF
body: <p>I am creating this TaskManager app, and I've set up the model class, dbcontext and form.</p>
  <p>When ever I press the submit button 2 times on the page itself, I get the following error:</p>
  <blockquote>
  <p>Microsoft.EntityFrameworkCore.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.'</p>
  </blockquote>
  <p>Inner exception :</p>
  <blockquote>
  <p>SqlException: Cannot insert explicit value for identity column in table 'Tasks' when IDENTITY_INSERT is set to OFF.</p>
  </blockquote>
  <pre><code>@page &quot;/task/createtask&quot;
  
  @inject AppDbContext _context;
  
  &lt;h3&gt;Create a Task&lt;/h3&gt;
  
  &lt;EditForm Model=&quot;@taskModel&quot; OnValidSubmit=&quot;@HandleValidSubmit&quot;&gt;
      &lt;DataAnnotationsValidator /&gt;
      &lt;ValidationSummary /&gt;
      &lt;div class=&quot;form-group&quot;&gt;
          &lt;label for=&quot;TitleTb&quot;&gt;Enter the title:&lt;/label&gt;
          &lt;InputText id=&quot;TitleTb&quot; class=&quot;form-control&quot; @bind-Value=&quot;taskModel.Title&quot;&gt;&lt;/InputText&gt;
          &lt;label for=&quot;DescTb&quot;&gt;Enter the description:&lt;/label&gt;
          &lt;InputText id=&quot;DescTb&quot; class=&quot;form-control&quot; @bind-Value=&quot;taskModel.Description&quot;&gt;&lt;/InputText&gt;
          &lt;label for=&quot;SelectTb&quot;&gt; &lt;span class=&quot;text-warning&quot;&gt;optional&lt;/span&gt; Enter the priority level:&lt;/label&gt;
          &lt;InputSelect id=&quot;SelectTb&quot; class=&quot;form-control&quot; @bind-Value=&quot;taskModel.ImportanceType&quot;&gt;
              &lt;option value=&quot;&quot;&gt;Select priority...&lt;/option&gt;
              &lt;option value=&quot;1&quot; class=&quot;text-danger&quot;&gt;Very important&lt;/option&gt;
              &lt;option value=&quot;2&quot; class=&quot;text-warning&quot;&gt;Can wait&lt;/option&gt;
              &lt;option value=&quot;3&quot; class=&quot;text-primary&quot;&gt;Not that important&lt;/option&gt;
          &lt;/InputSelect&gt;
          &lt;br/&gt;
          &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit!&lt;/button&gt;
      &lt;/div&gt;
  &lt;/EditForm&gt;
  
  @code {
      private TaskModel taskModel = new TaskModel();
  
      private void HandleValidSubmit()
      {
          taskModel.IsCompleted = false;
          taskModel.DateCreated = DateTime.Today;
  
          _context.Tasks.Add(taskModel);
          _context.SaveChanges();
      }
  }
  
  </code></pre>
  <p>Model and Context:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Threading.Tasks;
  
  namespace TaskManagerApp.Models
  {
      public class TaskModel
      {
          [Key]
          [Required]
          public int Id { get; set; }
          [Required]
          [MaxLength(20)]
          [MinLength(3)]
          public string Title { get; set; }
          [MaxLength(150)]
          [MinLength(5)]
          public string Description { get; set; }
          public DateTime DateCreated { get; set; }
          [Required]
          public bool IsCompleted { get; set; }
          public string ImportanceType { get; set; }
      }
  }
  
  </code></pre>
  <p>DbContext:</p>
  <pre><code>using Microsoft.EntityFrameworkCore;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using TaskManagerApp.Models;
  
  namespace TaskManagerApp.Data
  {
      public class AppDbContext : DbContext
      {
          public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options) : base(options)
          {
  
          }
  
          public DbSet&lt;TaskModel&gt; Tasks { get; set; }
      }
  }
  </code></pre>
  <p>Also I am using 2 dbcontexts, one from the Microsoft authentication system identity and another one that I created called <code>AppDbContext</code>.</p>
  <p>Is there any way to solve it? If yes I would really appreciate your help!</p>
  <p>Thank you!</p>