I have a Save() method that saved rows using a Linq2Sql DataContext.
private void Save(object sender, EventArgs e)
{
Validate();
selectNumUnitsByPidCdCostRevBindingSource.EndEdit();
var db = new AccountingDataClassesDataContext(true);
unitCountDataSet
.GetChanges(DataRowState.Modified).Tables[0].Rows
.Cast<EomApp1.Formss.Accounting.Data.UnitCountDataSet.SelectNumUnitsByPidCdCostRevRow>().ToList()
.ForEach(row =>
{
db.Items.First(item => item.id == row.id).num_units = row.num_units;
});
db.SubmitChanges();
Fill();
}
This is the first time I’ve ever really wanted to ensure multiple updates occurred as a single batch (all or nothing) – and I’m just not sure if result of SubmitChanges() will be so.
If the answer is no, then what is the way to put this into a transaction?
The SubmitChanges() call will create a new transaction if one does not already exist, so yes these changes will be atomic.
Basically you’re in the third case as described in these docs:
http://msdn.microsoft.com/en-us/library/bb386995(v=vs.90).aspx