无法更新 EntitySet - 因为它有一个 DefiningQuery 并且没有 <UpdateFunction>元素存在 [英] Unable to update the EntitySet - because it has a DefiningQuery and no <UpdateFunction> element exist

查看:31
本文介绍了无法更新 EntitySet - 因为它有一个 DefiningQuery 并且没有 <UpdateFunction>元素存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Entity Framework 1 和 .net 3.5.

I am using Entity Framework 1 with .net 3.5.

我正在做这样简单的事情:

I am doing something simple like this:

var roomDetails = context.Rooms.ToList();

foreach (var room in roomDetails)
{        
   room.LastUpdated = DateTime.Now;
}

当我尝试执行此操作时出现此错误:

I am getting this error when I try to do:

 context.SaveChanges();

我收到错误:

无法更新 EntitySet - 因为它有一个 DefiningQuery 并且没有 <UpdateFunction>元素存在于<ModificationFunctionMapping>中.元素来支持当前操作.

我正在对上下文进行大量更新并且没有任何问题,只有当我尝试更新此特定实体时才会出现.

I am doing lots of updates on the context and not having any issues, it's only when I try to update this particular entity.

我所有的搜索都显示相同的内容,即在我尝试更新的实体上没有声明主键.但是,唉,我确实有一个主键声明...

All my searching shows up the same thing, that there is no primary key declared on the entity that I'm trying to update. But alas, I do have a Primary key declared...

推荐答案

这通常是由于以下原因之一造成的:

It usually happens because one of the following reasons:

  • 实体集是从数据库视图映射的
  • 自定义数据库查询
  • 数据库表没有主键

执行此操作后,您可能仍需要在实体框架设计器中进行更新(或者删除实体然后添加它),然后才能停止出现错误.

After doing so, you may still need to update in the Entity Framework designer (or alternatively delete the entity and then add it) before you stop getting the error.

这篇关于无法更新 EntitySet - 因为它有一个 DefiningQuery 并且没有 &lt;UpdateFunction&gt;元素存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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