Why does this EF insert with IDENTITY_INSERT not work?
问题 This is the query: using (var db = new AppDbContext()) { var item = new IdentityItem {Id = 418, Name = "Abrahadabra" }; db.IdentityItems.Add(item); db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Test.Items ON;"); db.SaveChanges(); } When executed, the Id of the inserted record, on a new table, is still 1. NEW: When I use either the transaction, or TGlatzer's answer, I get the exception: Explicit value must be specified for identity column in table 'Items' either when IDENTITY_INSERT is