当我尝试更新实体框架中的模型时,为什么会出现“无法更新实体集,因为它有 DefiningQuery...”异常?

2024-03-19

使用实体框架借助 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.问题将会得到解决

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当我尝试更新实体框架中的模型时,为什么会出现“无法更新实体集,因为它有 DefiningQuery...”异常? 的相关文章

随机推荐