无法更新的EntitySet - 因为它有一个DefiningQuery和无&其中; UpdateFunction>元素存在 [英] Unable to update the EntitySet - because it has a DefiningQuery and no <UpdateFunction> element exist

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

问题描述

我使用实体框架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 Rooms)
{        
   Room.LastUpdated = DateTime.Now;
}

我收到此错误,当我尝试这样做:

I am getting this error when I try to do:

 context.SaveChanges();

我得到的错误:

I get the error:

无法更新EntitySet的 - 因为它有一个DefiningQuery并没有与LT; UpdateFunction>元件中存在的<&ModificationFunctionMapping GT;元素来支持当前的操作。

我在做大量的上下文更新,并没有任何问题,只有当我尝试更新这个特定的实体。

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 if entity set is mapped from database view, custom database query or if database table doesn't have primary key.

这样做之后,您可能仍然需要在实体框架设计更新(或者删除该实体,然后添加它),然后再停止得到的错误。

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和无&其中; UpdateFunction>元素存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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