Bulk insert using AddRange in Entity framework

c# entity-framework

Question

I'm utilizing the database to add several entities.AddRange using Entity Framework

foreach (string tagNumber in notPresent)
{
    element = new TagMaster { Name = Guid.NewGuid().ToString(), IsActive = true };
    element.TagCollections.Add(new TagCollection { TagNumber = tagNumber });
    newTagMasters.Add(element);
}
dbContext.TagMasters.AddRange(newTagMasters);
dbContext.SaveChanges();

I anticipated that by including the entire collection in context utilizingAddRange approach, the database would only receive a single query. To my amazement, I discover that each record that needs to be inserted has numerous insert statements.

Any Suggestions?

1
0
10/27/2015 1:09:57 PM

Popular Answer

ZZZ_tmp
3
10/27/2015 9:20:32 PM


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