Bulk Insert in Entity Framework v6.1

asp.net-mvc-5.1 c# entity-framework-6


Our is a healthcare application follows (AngularjS+MVC+WebAPI) 3tier architecture. Im uploading an Excel sheet n doing column mappings in an import screen. After that im doing all validations for each n every record in the excel sheet. Afterwards all these 50K rows as entities to Web-API layer. Here im inserting one rec into the parent table to get the primary key. After getting it im looping through the 50k entities to update it in the collection. Then im using addRange to update all these values into the database. Here is a piece of code we have used in the application.



            (Primary Key) fileId = int.Parse(Entity1.Id.ToString());

//DataList having 50K Entities
            foreach (tableB coll in DataList)


                coll.fileID = fileId;                    




Referred below links. Bulk insert in entity framework

How to use Bulk Insert in Entity Framework using Object Context?

Bulk insert in entity framework

But i couldnt use the EntityFramework.BulkInsert since its not compatible with the latest EF version(6.1). Is there any other viable approach to use bulk insert using EF? Also can we use SqlBulkCopy in the Entity Framework?`

5/23/2017 10:27:45 AM

Expert Answer

Here is an alternative solution by using another third party library (Compatible with Entity Framework 6.1)

Disclaimer: I'm the owner of the project Entity Framework Extensions

This library is compatible with all Entity Framework Version 6.X

It does more than only Bulk Inserting by allowing to do all bulk operation your application may requires:

  • BulkSaveChanges
  • BulkInsert
  • BulkUpdate
  • BulkDelete
  • BulkMerge


// Easy to use

// Easy to customize
context.BulkSaveChanges(bulk => bulk.BatchSize = 100);

The library support all kind of inheritance and association, however, the library is not free.

9/28/2016 3:22:40 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow