linq to sql的修改报错
try
{
DepotDataContext dataContxt = CommentParameter.DepotContext;
var vardate = from a in dataContxt.S_MessMessageFeedback
where a.DJH == InLnqMess.DJH
select a;
if (vardate.Count() == 1)
{
S_MessMessageFeedback lnqMess = vardate.Single();
lnqMess.SQEvalidateMessage = InLnqMess.SQEvalidateMessage;
lnqMess.SQEYZRY = BasicInfo.UserName;
lnqMess.SQEYZRQ = InLnqMess.SQEYZRQ;
lnqMess.DJZT = "等待质管部确认";
break;
default:
break;
}
dataContxt.SubmitChanges();
}
}
catch (Exception ex)
{
m_err = ex.Message;
return false;
throw;
}
然后报错:无法附加已存在的实体!
才开始学习linq to sql,所以请各位帮忙看一下,是不是还有什么没有写??
------解决方案-------------------- break;
default:
break;
写这些是什么意思?
------解决方案-------------------- C# code
try
{
DepotDataContext dataContxt = CommentParameter.DepotContext;
var vardate = dataContxt.S_MessMessageFeedback.SingleOrDefault(a=>a.DJH == InLnqMess.DJH);
if vardate !=null)
{
vardate .SQEvalidateMessage = InLnqMess.SQEvalidateMessage;
vardate .SQEYZRY = BasicInfo.UserName;
vardate .SQEYZRQ = InLnqMess.SQEYZRQ;
vardate .DJZT = "等待质管部确认";
dataContxt.SubmitChanges();
}
}
catch (Exception ex)
{
m_err = ex.Message;
return false;
throw;
}
------解决方案-------------------- 探讨 try { DepotDataContext dataContxt = CommentParameter.DepotContext; var vardate = from a in dataContxt.S_MessMessageFeedback ……
------解决方案-------------------- 用 FirstOrDefault