开发者

Linq to SQL: How to get values added thru InsertOnSubmit but before SubmitChanges?

开发者 https://www.devze.com 2022-12-17 23:06 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号