Remove Auto Increment in EF Core 1.0 RC2 (former EF 7 RC2)

后端 未结 2 1985
孤城傲影
孤城傲影 2021-01-13 19:44

In Entity Framework Core 1.0 RC2 (former Entity Framework 7 RC2), by default, all integer primary key are auto increment field. I tried everything to remove

相关标签:
2条回答
  • 2021-01-13 20:24

    In EF Core, key and property are configured separately.

    To specify the key:

    modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId);
    

    To configure the property not being auto increment:

    modelBuilder.Entity<tblProduct>().Property(t => t.ProdId).ValueGeneratedNever();
    
    0 讨论(0)
  • 2021-01-13 20:34

    I did not work with EF 7 but few points to check

    • After you changed the model you need to update database, migration or manually
    • Check in database if you have now autoincrement on field
    0 讨论(0)
提交回复
热议问题