Linq to SQL: How to get values added thru InsertOnSubmit but before SubmitChanges?
Having trouble getting this. I need get the values that I have added to a table entity through the InsertOnSubmit method. However I have not yet invoked SubmitChanges on the table.
So, I have this in a loop: mdmDC.tblMDMListItems.InsertOnSubmit(listItemsTable);
But I'd like to query mdmDC.tblMDMListItems for some values entered so fa开发者_如何学Gor, yet I cannot seem to do that. Even after that code above the count on mdmDC.tblMDMListItems is 0.
How can I get the values added before SubmitChanges?
Thanks!!
Use DataContext.GetChangeSet
and the ChangeSet.Inserts
property.
// db is DataContext
ChangeSet cs = db.GetChangeSet();
foreach(var item in cs.Inserts) {
// do something
}
Note that item
is not strongly-typed. In fact, it can not be because the DataContext
could be tracking items of differing types corresponding to multiple tables.
精彩评论