0

Is there any maximum size / number of records that can be added to database table with EntityFramework without problems with using a single context.SaveChanges() after?

Imagine that we have an entity:

public class DbEntity
{
    public int DbEntityId {get;set;}
    public decimal Value {get; set;}
    public string Text {get; set;}
}

And now we would like to add a huge collection of DbEntity items into database table, like:

var collection = new DbEntity[99999]; // data initialization ommited
context.DbEntities.AddRange(collection);

And then single call:

context.SaveChanges();

Should it be fine, or we should split the data that is about to be added into db and handle it in as a chunks ->

context.DbEntities.AddRange(collection.Take(1000));
context.SaveChanges();
context.DbEntities.AddRange(collection.Skip(1000).Take(1000));
context.SaveChanges();

etc?

pitersmx
  • 935
  • 8
  • 27
  • EF shouldn't have problems with huge injections. The only reason to split it into chunks is to locate possible errors more easy and the performance. – Cataklysim Oct 16 '17 at 09:59
  • 1
    this is possibly a duplicate of https://stackoverflow.com/questions/5940225/fastest-way-of-inserting-in-entity-framework Maybe it can help you. – Igor Jakovljevic Oct 16 '17 at 10:01

0 Answers0