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?
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));