LINQ TO SQL 删除操作时报错“找不到行或行已更改”

表所有字段为非空

加载ID主键

protected void Page_Load(object sender, EventArgs e)
    {
        HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext();
       ENTUserAccount useraccount= db.ENTUserAccount.Single(ua => ua.WindowsAccountName == @"VARALLO1\VaralloMadison");

       ViewState["ENTUserAccountID"] = useraccount.ENTUserAccountID;
          }

 

执行删除:

 protected void Button4_Click(object sender, EventArgs e)
    {
        HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext();
        try
        {
            db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
        }

        catch (System.Data.Linq.ChangeConflictException ex)
        {
            foreach (System.Data.Linq.ObjectChangeConflict occ in db.ChangeConflicts)
            {
                occ.Resolve(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
            }
        }
        ENTUserAccount useraccount = new ENTUserAccount();

        useraccount.ENTUserAccountID = Convert.ToInt32(ViewState["ENTUserAccountID"]);
      

        db.ENTUserAccount.Attach(useraccount);
        db.ENTUserAccount.DeleteOnSubmit(useraccount);
        db.SubmitChanges();//此处报错“找不到行或行已更改”

    }

没做更新,是否删除也要添加时间戳?

当年话下
浏览 868回答 3
3回答

青春有我

是不是这行已经更改了啊 db.ENTUserAccount.DeleteOnSubmit(useraccount);
打开App,查看更多内容
随时随地看视频慕课网APP