Created
July 27, 2011 10:43
-
-
Save kristofclaes/1109126 to your computer and use it in GitHub Desktop.
I don't like this, but I don't want to add too much business logic to a stored procedure either. How can this be improved?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var context = new DbContext(); | |
foreach(var itemId in itemIds) // on average about 10 items | |
{ | |
var item = new Item(); | |
item.ForeignKey = itemId; | |
item.SomeProperty = someValue; | |
foreach(var subItemId in subItemsIds) // on average about 20 subitems | |
{ | |
var subItem = new SubItem(); | |
subItem.ForeignKey = subItemId; | |
subItem.SomeProperty = someValue; | |
foreach(var date in dates) // on average about 30 dates | |
{ | |
var subSubItem = new SubSubItem(); | |
subSubItem.Date = date; | |
subSubItem.SomePropery = someValue; | |
subItem.SubSubItems.Add(subSubItem); | |
} | |
item.SubItems.Add(subItem); | |
} | |
context.Items.Add(item); | |
} | |
context.SaveChanges(); // about 6.100 inserts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment