Why EF SaveChanges
is going to insert/delete each record in a separate query?
Suppose this code:
using (var db = new AppEntities())
{
using (var transaction = db.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
{
try
{
db.Table1.AddRange(list);
db.Table2.RemoveRange(list);
}
db.SaveChanges();
transaction.Commit();
}
}
I check these lines with SQL Server Profiler, and surprisingly there is one INSERT INTO
per each record! And worse than that, the same was for delete! This is not a serious problem for 100 rows. But with 5000 rows it takes 2 minutes!
Is it possible to tell EF, PLEASE do this in following way :
INSERT INTO TABLE1 VALUES (),(),(),();