I have an entity that has an Auto-identity (int)
column. As part of the data-seed I want to use specific identifier values for the \"standard data\" in my syste
According to this previous Question you need to begin a transaction of your context. After saving the change you have to restate the Identity Insert column too and finally you must have to commit the transaction.
using (var transaction = context.Database.BeginTransaction())
{
var item = new ReferenceThing{Id = 418, Name = "Abrahadabra" };
context.IdentityItems.Add(item);
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Test.Items ON;");
context.SaveChanges();
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[User] OFF");
transaction.Commit();
}