Bulk insert records and get their Id's after bulk insert in Entity Framework

c# entity-framework entity-framework-6 sql

Expert Answer

There doesn'tBulk Insert Entity Framework, For this type of activity, a third-party library is required.

Every time an entity is saved, Entity Framework by default does a round trip to the database. Therefore, in your situation, more than 100,000 database round-trips will be needed, which is INSANELY sluggish.


I possess Extended Entity Framework, which is Disclaimer.

Although this library costs money, it lets you execute any bulk operations, includingBulkInsert and automatically return theId's Additionally, you may include a linked object usingIncludeGraph options:

  • SaveChanges in bulk
  • a mass insert
  • mass deletion
  • Mass Update
  • mass merge

Example

// Easy to use
context.BulkSaveChanges();

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

// Perform Bulk Operations
context.BulkDelete(customers);
context.BulkInsert(customers);
context.BulkUpdate(customers);

// Customize Primary Key
context.BulkMerge(customers, operation => {
   operation.ColumnPrimaryKeyExpression = 
        customer => customer.Code;
});

Answer all of the questions

Are those the same bits as "EF Plus"

Also, I am the proprietor of Plus Entity Framework

In essence, we divided features into two libraries: free and premium. EF+ does not assistBulk Operations .

Only one functionality is presently shared by both libraries.Batch Delete and Batch Update

0
11/2/2017 1:13:29 AM


Related Questions





Related

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