2

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.

Reddog
  • 15,219
  • 3
  • 51
  • 63
horace
  • 938
  • 9
  • 20
  • If you are trying to make it transactional, then use the `TransactionScope`. – Ilia G Jan 14 '12 at 04:06
  • @liho1eye there is no need to use transactionscope. l2s does all this for you as long as you have only one SubmitChanges – Pleun Jan 14 '12 at 20:39

1 Answers1

4

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.

James Manning
  • 13,429
  • 2
  • 40
  • 64