asp.net-mvc – 为什么我得到一个“无法更新EntitySet,因为它有一个定义查询…”异常时,试图更新在En

在使用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。问题将得到解决

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。