无法更新的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();for...

我使用实体框架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.

阅读全文

相关推荐

最新文章