为什么我得到一个“无法更新EntitySet因为它有一个DefiningQuery ...”尝试更新实体框架中的模型时出现异常? [英] Why am I getting a "Unable to update the EntitySet because it has a DefiningQuery..." exception when trying to update a model in Entity Framework?

查看:140
本文介绍了为什么我得到一个“无法更新EntitySet因为它有一个DefiningQuery ...”尝试更新实体框架中的模型时出现异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用实体框架的LINQ to SQL帮助下更新时,会抛出异常。

While updating with the help of LINQ to SQL using Entity Framework, an exception is thrown.

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)
        {

        }
    }

为什么我得到这个错误?

Why am I getting this error?

推荐答案

问题出在表结构体。 为避免错误,我们必须在表中设置一个主键。之后,更新edmx。问题将被修复

The problem was in the table structure. To avoid the error we have to make one primary key in the table. After that, update the edmx. The problem will be fixed

这篇关于为什么我得到一个“无法更新EntitySet因为它有一个DefiningQuery ...”尝试更新实体框架中的模型时出现异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆