我正在检查重复项,它发现它们并且 If(isDuplicate) 一切正常。但是代码继续执行所有提交,因为我没有告诉它停止。我该怎么做?停止并抛出它确实但未提交的错误面板?
_db.tbl_Localities.InsertOnSubmit(locality);
bool isDuplicate = _db.tbl_Localities
.Any(x => x.Locality == txt_Locality.Text);
if (isDuplicate)
{
pnl_Message.Visible = true;
lbl_message.Text = " Duplicate entry!";
txt_Locality.Text = "";
}
// Save
// ====
_db.SubmitChanges();