Hi @sblb
By default, for the primary key, the identity key's identity seed is 1 and identity increment is 1. You can view the table design via SSMS and check the identity setting.
why the increment of ActionItemId is 1 and after 1002 ???
If you are using the default identity setting (both the identity seed and identity increment is 1), after inserting the first item(ActionItemId is 1), you might installed 1001 items in the ActionItems and these items are inserted has been removed or installed fail. So, when insert the items, the next item's ActionItemId is 1002, 1003...
Like this:
If the identity increment is set to 1001 (check the table design, and the T-SQL script: Identity(1,1001)), after insert the first item(ActionItemId is 1), the next item's ActionItenId is 1002, 2003, 3004...
About how to set the identity increment, you can change it from the table design: directly change the T-SQL script and then click the Update button to change the database.
Besides, you can also set identity column in the DbContext's OnModelCreating method, like this:
public class ApplicationDbContext : IdentityDbContext
{
public DbSet<ActionItem> ActionItems { get; set; }
#region
//public DbSet<Customer> Customers { get; set; }
//public DbSet<Professional> Professionals { get; set; }
//public DbSet<Account> Accounts { get; set; }
public DbSet<A> A { get; set; }
public DbSet<B> B { get; set; }
public DbSet<C> C { get; set; }
#endregion
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
//set the primary key
builder.Entity<ActionItem>().HasKey(c => c.ActionItemId);
//set the identity column: identity increment and identity seed
builder.Entity<ActionItem>().Property(c => c.ActionItemId).UseIdentityColumn(1, 1001);
#region
//builder.Entity<Account>(entity => { entity.ToTable("Accounts"); });
//builder.Entity<Customer>(entity => { entity.ToTable("Customers"); });
//builder.Entity<Professional>(entity => { entity.ToTable("Professionals"); });
#endregion
}
Then, the generated table design as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion