在使用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)
{
}
}
为什么我收到此错误?
解决方法
问题出在表结构中。为了避免错误,我们必须在表中创建一个主键。之后,更新edmx。问题将得到解决
