【发布时间】:2023-04-07 13:43:02
【问题描述】:
在使用 Entity Framework 借助 LINQ to SQL 进行更新时,会引发异常。
System.Data.UpdateException: Unable to update the EntitySet 't_emp' because it has
a DefiningQuery and no <UpdateFunction> element exists in the
<ModificationFunctionMapping>
更新代码为:
public void Updateall()
{
try
{
var tb = (from p in _te.t_emp
where p.id == "1"
select p).FirstOrDefault();
tb.ename = "jack";
_te.ApplyPropertyChanges(tb.EntityKey.EntitySetName, tb);
_te.SaveChanges(true);
}
catch(Exception e)
{
}
}
为什么会出现这个错误?
【问题讨论】:
标签: asp.net-mvc entity-framework linq-to-sql exception