Cannot insert the value NULL into column in ASP.NET MVC Entity Framework

前端 未结 3 1968
天命终不由人
天命终不由人 2020-12-31 03:32

When trying to use this code:

var model = new MasterEntities();

var customer = new Customers();
customer.Sessionid = 25641;

model.Customers.Add(customer);
         


        
3条回答
  •  滥情空心
    2020-12-31 03:52

    You can configure SQL to auto-generate (and auto-increment) the primary key for the table upon inserts. Then just remove the [Key] in C# and you don't need to set the ID in the application manually, the db will generate it for you.

提交回复
热议问题