0

We have a huge EF context model. I want to bulk insert data from one parent table and its child table only. BulkSaveChanges is taking too long and I'm playing with BulkInsert but when I set options.IncludeGraph = true then it is taking even longer. Is there a way to prevent Dapper from searching all related objects and only insert data from a Parents table and from Child?

LINQ2Vodka
  • 2,996
  • 2
  • 27
  • 47

1 Answers1

1

Can you call twice the bulk insert? One for parents, one for their childs

context.BulkInsert(parents);
context.BulkInsert(parents.SelectMany(x => x.Childs));

After parents have been inserted, the childs still have ParentId = 0

We hope to soon improve this part but at this moment, you need to assign ParentId to your child.

For example:

context.BulkInsert(parents);
parents.ForEach(x => x.Childs.ForEach(y => y.ParentID = x.ID));
context.BulkInsert(parents.SelectMany(x => x.Childs));
Jonathan Magnan
  • 10,874
  • 2
  • 38
  • 60
  • Hello Johnatah, thanks for reply! Unfortunately this doesnt work for me... After parents have been inserted, the childs still have ParentId = 0 and it gives FK constraint exception in line #2. Am I doing something wrong? – LINQ2Vodka Feb 08 '19 at 13:28