Entity Framework auto increment with starting value

后端 未结 3 433
刺人心
刺人心 2020-12-17 05:07

I have a entity as follows

[Table(\"ESS_POS_SE_VERSION\")]
public class Version
{
    [Key, Column(\"DETAIL_ID\"), DatabaseGenerated(DatabaseGeneratedOption.         


        
3条回答
  •  悲&欢浪女
    2020-12-17 05:29

    There is no way to set through Property or Attribute. However, you can run the command on this event:

    Probably you can set through Alter: ALTER TABLE [MyTable] ALTER COLUMN [IdentityColumn] IDENTITY (1000,1).

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        { context.Database.ExecuteSqlCommand(ALTER TABLE [MyTable] ALTER COLUMN [IdentityColumn] IDENTITY (1000,1)) }
    

提交回复
热议问题