MikaelEliasson / EntityFramework.Utilities

Provides extensions for EntityFramework that doesn't exist out of the box like delete and update by query and bulk inserts
443 stars 175 forks source link

Enabling identity insert for InsertAll() #110

Open phillijw opened 7 years ago

phillijw commented 7 years ago

For some reason I am not able to enable identity insert, do the bulk insert, then disable it again. Am I doing something wrong or is this a bug?

db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Orders] ON");
EFBatchOperation.For(db, db.Orders).InsertAll(olist);
db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Orders] OFF");

This code ignores the value I've set on the model and uses the next available seeded record in the table.