I have code in which I use a DataContext Linq-To-SQL to add and modify records in a table.
I came across a situation where I add several records through InsertOnSubmit and then I want to change the record .. but this record may already be in the table, or it may be one of those that I insert, So:
db.MyTable.Single(t => t.Id == WhichId).Name="foobar";
It may not work, since I may not have inserted an entry with WhichId identifier WhichId .
I really don't want SubmitChanges() until I have done everything I do.
The DataContext should contain a list of records that need to be inserted into SubmitChanges () - can I access this list? I am 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 square brackets are enclosed?
source share