According to the previous Question, you need to start a transaction of your context. After saving the change, you should also copy the Identity Insert column, and finally you must commit the transaction.
using (MCT_DB_ArchiveEntities ent = new MCT_DB_ArchiveEntities()) using (var transaction = ent.Database.BeginTransaction()) { var item = new User {Id = 418, Name = "Abrahadabra" }; ent.IdentityItems.Add(item); ent.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Test.Items ON;"); ent.SaveChanges(); ent.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[User] OFF"); transaction.Commit(); }
gdmanandamohon
source share