Disabling identity (auto-incrementing) on integer primary key using code first

后端 未结 7 1339
孤街浪徒
孤街浪徒 2020-12-01 10:13

I am using code first approach in a ASP.NET MVC 3 application and all integer primary keys in models (public int Id { get; set; }) are by default configured as

7条回答
  •  没有蜡笔的小新
    2020-12-01 10:46

    If this is an identity field in the database you cant. Well you can by setting identity insert off on the database side but by good practice you shouldn't unless bulk inserting records. If you don't want this as an identity set the identity option to false in the DB for that column.

提交回复
热议问题