1
//SelectUtilitiesCheckbox is bound to a complete list of the Utilitie_companies table
foreach (ListItem x in SelectUtilitiesCheckBox.Items)
{
Select_Utility SU = rows.Where(r => r.Utility_Id == Convert.ToInt32(x.Value)).FirstOrDefault();
bool initialValue = SU != null;
if (x.Selected == true && initialValue == false)
{
// New qualification added so save it
Select_Utility NewSelectUtility = new Select_Utility();
NewSelectUtility.WorkId = tempWorkSiteId;
NewSelectUtility.Utility_Id = System.Convert.ToInt32(x.Value);
context.Select_Utilities.InsertOnSubmit(NewSelectUtility);
}
else if (x.Selected == false && initialValue == true)
{
// Removed old qualification so remove it in the database
context.Select_Utilities.DeleteOnSubmit(SU);
}
}
context.SubmitChanges();
我的Q是 - 使用LINQ - 將在提交作品很好,但是當我嘗試使用deleteOnSubmit我得到一個DeleteOnSubmit - 未找到行或更改
ERROR: ChangeConflictEception was unhandled by user code - Row not found or changed.
當它到達context.submit但在上下文中使用breakpoit'Su'.Select_Utilities.DeleteOnSubmit(SU);包含刪除正確的記錄
任何想法爲什麼?