Bulk insert using EntityFramework Extended

Luis Teijon picture Luis Teijon · Apr 2, 2017 · Viewed 10.7k times · Source

According to this, bulk insert in Entity can be made using the following code:

 var customers = GetCustomers();   
 db.Customers.AddRange(customers);   
 db.SaveChanges();  

I used SQL Profiler to verify how many insert queries were executed and I saw there was an insert for each element of the list.

enter image description here

Why?

Answer

abatishchev picture abatishchev · Apr 2, 2017

That's how EF6 does "bulk" insert, it doesn't do in bulk, rather row by row. As a result performance sucks.

Use EF.BulkInsert or EFUtilities instead.

Update:

DbSet<T>.AddRange() is a part of the built-in API, this way you don't use EF.Extended or any other 3rd party library.