表所有字段为非空
加载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();//此处报错“找不到行或行已更改”
}
没做更新,是否删除也要添加时间戳?
晕,不出所料,要添加Version字段的!
是不是这行已经更改了啊 db.ENTUserAccount.DeleteOnSubmit(useraccount);
没有更改只做过插入操作,我想把插入的删除了,才发现这个问题,插入的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext();
ENTUserAccount useraccount = new ENTUserAccount
{
WindowsAccountName = @"VARALLO1\VaralloMadison",
FirstName = "Madison",
LastName = "Varallo",
Email = "madison.varallo@v2.com",
IsActive = true,
InsertDate = DateTime.Now,
InsertENTUserAccountID = 1,
UpdateDate = DateTime.Now,
UpdateENTUserAccountID = 1
};
db.ENTUserAccount.InsertOnSubmit(useraccount);
db.SubmitChanges();