Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch update/delete EF5

What is the best way to deal with batch updates using (Entity Framework) EF5? I have 2 particular cases I'm interested in:

  1. Updating a field (e.g. UpdateDate) for a list (List) of between 100 and 100.000 Id's, which the primary key. Calling each update separately seem to be to much overhead and takes a long time.

  2. Inserting many, also between the 100 and 100.000, of the same objects (e.g. Users) in a single go.

Any good advice?

like image 362
Frank Avatar asked Oct 05 '12 17:10

Frank


1 Answers

  1. There are two open source projects allowing this: EntityFramework.Extended and Entity Framework Extensions. You can also check discussion about bulk updates on EF's codeplex site.
  2. Inserting 100k records through EF is in the first place wrong application architecture. You should choose different lightweight technology for data imports. Even EF's internal operation with such big record set will cost you a lot of processing time. There is currently no solution for batch inserts for EF but there is broad discussion about this feature on EF's code plex site.
like image 144
Ladislav Mrnka Avatar answered Oct 03 '22 21:10

Ladislav Mrnka