gpt4 book ai didi

asp.net-mvc - 为什么在 Entity Framework 中尝试更新模型时会收到 "Unable to update the EntitySet because it has a DefiningQuery..."异常?

转载 作者:行者123 更新时间:2023-12-03 10:48:30 24 4
gpt4 key购买 nike

使用 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。问题将被修复

关于asp.net-mvc - 为什么在 Entity Framework 中尝试更新模型时会收到 "Unable to update the EntitySet because it has a DefiningQuery..."异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6774871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com