Cannot insert explicit value for identity column in table 'XYZ' when IDENTITY_INSERT is set to OFF.
Solution:
If you work on ASP .Net vNext with MVC 6.0 and EF 7.0 beta, welcome to hell :-))
It's was kidding.
Solution 1 is add [DatabaseGenerated(DatabaseGeneratedOption.None)] annotation to your ID of your Table (class model)
Solution 2 is add below line to OnModelCreating override method of your DbContext
builder.Entity<XYZ>().Property(i => i.Id).GenerateValuesOnAdd(generateValues: false);
No comments:
Post a Comment