Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a Bulk Insert -- Linq to Entities

I cannot find any examples on how to do a Bulk/batch insert using Linq to Entities. Do you guys know how to do a Bulk Insert?

like image 377
Luke101 Avatar asked Oct 22 '09 18:10

Luke101


People also ask

What is bulk insert in Entity Framework?

The EF Bulk Insert feature let you insert thousands of entities in your database efficiently. This feature is provided by the library EF Extensions (Included with EF Classic). EF Extensions is used by over 2000 customers all over the world and supports all Entity Framework versions (EF4, EF5, EF6, EF Core, EF Classic).

What is the best and fast way to insert 2 million rows of data into SQL Server?

You can try with SqlBulkCopy class. Lets you efficiently bulk load a SQL Server table with data from another source.

Is bulk insert faster than insert?

Bulk insert is generally much faster.


1 Answers

Sometimes you simply have to mix models. Perhaps use SqlBulkCopy for this part of your repository (since this plugs directly into the bulk-copy API), and Entity Framework for some of the rest. And if necessary, a bit of direct ADO.NET. Ultimately the goal is to get the job done.

like image 166
Marc Gravell Avatar answered Sep 19 '22 00:09

Marc Gravell