简体   繁体   中英

Can I access the list of InsertOnSubmit'd records from a linq-to-sql DataContext?

I have some code where I am using a Linq-To-SQL DataContext to add and modify records in a table.

I've run into a situation where I add a few records via InsertOnSubmit, and then I want to modify a record.. but this record may already be in the table, or it may be one of the ones I am inserting. So this:

db.MyTable.Single(t => t.Id == WhichId).Name="foobar";

Might not work, since I might not have actually inserted the record with an Id of WhichId yet.

I don't really want to SubmitChanges() until I've done everything I'm going to do.

The DataContext must keep a list of records to be inserted on SubmitChanges() - can I access that list? I'm thinking of something like this:

(db.MyTable.SingleOrDefault(t => t.Id == WhichId) ??
 db.[list of records to be inserted].Single(t => t.Id == WhichId)
).Name="foobar";

So the question is, is there anything I can put where those square brackets are?

db.GetChangeSet().Inserts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM