linq delete, insert, submit

863 views Asked by At

i am wondering if i need to continually call SubmitChanges() when i run sequential delete/insert statements on the same data store:

db.SomeTable.DeleteAllOnSubmit( db.SomeTable.Where( p => p.PartID == part.PartID ) );
db.SubmitChanges();

List<SomeTable>     alist = new List<SomeTable>();

foreach ( GenericLookupE item in part.PublicAssistance )
{
    alist.Add( new SomeTableEntity() { . . . } );
}

db.SomeTable.InsertAllOnSubmit( alist );
db.SubmitChanges();

basically, all the values i am storing in this table are checkbox results (One Participant to Many Checkboxes). so i delete everything in the table for that participant and create a list to insert 'en-masse'.

not sure if i'm stating this clearly or not.

put another way, if i do the DeleteAllOnSubmit without calling SubmitChanges, then call the InsertAllOnSubmit and finally call SubmitChanges, would it work as expected?

thanks.

1

There are 1 answers

0
James Manning On BEST ANSWER

Yes, it would work correctly, and doing all the changes and SubmitChanges only once is generally considered better than the alternative of submitting them separately.