//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 时,我得到一个
错误:用户代码未处理 ChangeConflictEception - 未找到或更改行。
当它到达 context.submit 但在 context.Select_Utilities.DeleteOnSubmit(SU) 中使用断点“Su”; 包含要删除的正确记录
关于为什么的任何想法?