自我跟踪实体 - AcceptChanges不能继续,因为对象的键值与ObjectStateManager中的另一个对象冲突 [英] Self Tracking Entities - AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager

查看:766
本文介绍了自我跟踪实体 - AcceptChanges不能继续,因为对象的键值与ObjectStateManager中的另一个对象冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遇到这个问题了一个多星期了。希望有人可以指出我正确的方向。

I've been stuck with this problem for over a week now. Hopefully some one can point me in the right direction.

我首先简要介绍了我的架构。

I start with a brief description of my schema.

资产1 ---> 1地址* - > 1区域* - > 1区域* - > 1国家

Asset 1--->1 Address *-->1 Area *-->1 Region *-->1 Country

包1 - > *资产

Package 1-->* Asset

使用自我跟踪实体(STE)+ WCF。

Using Self Tracking Entity (STE) + WCF.

步骤:


  1. 拨打资料清单的资料储存。

  2. 致电数据存储,查看包裹清单。

  3. 用户选择包裹并分配一些资产。

  4. 保存包裹。

  1. Call data store for a list of assets.
  2. Call data store for a list of packages.
  3. User selects a package and assign some assets to it.
  4. Save package.

在步骤2中,该呼叫使用热切地加载地址。

In step 2, the call uses eager loading of Addresses.

from p in context.Assets.Include("Address.Area.Region.Country")

这是尝试调用

context.Packages.ApplyChanges(package)




AcceptChanges不能继续,因为
对象的键值与
ano冲突
ObjectStateManager中的对象。调用
AcceptChanges之前,确保
键值是唯一的。

AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.

编辑

在窥探之后,我发现这是一个STE问题。问题是您不能保留包含与概述这里。这是我的问题。

After snooping around, i found that this is a STE issue. The problem being you cannot persist a graph that contains multiple instances of the same entity as outlined here. Here is my question.


如何将实体添加到我的实体
集合。新实体可能具有
相关实体,其中包含与集合中已有的
密钥相同的
密钥。
I.e添加一个新资产,可能包含
相同的地址,区域,区域或
国家实体。

How can I add an entity to my entity collection. The new entity may have related entities that contain the same key as one already in the collection. I.e. Add a new asset that may contain the same address, area, region or country entity.

这里是我的约束:


  1. 我必须使用导航集合,因为它影响UI。

  2. 我不能预先获取所有涉及的实体,因为数据集太大了。

  3. 我可以随时拍摄实体的快照,以保留历史记录并且使用它来撤消任何更改。

我知道由 Diego B Vega ,但这些不是我可以用于我的解决方案的选项。有人有任何其他想法吗?

I am aware of the possible solutions suggested by Diego B Vega, but those are not options i can use for my solution. Has anyone any other ideas?

推荐答案

FYI,我写了一篇博客文章,并提供了一些额外的建议, EF论坛这里是博客文章。

FYI, I wrote a blog post with some additional suggestions to what I had already responded in the EF Forums. Here is the blog post.

这篇关于自我跟踪实体 - AcceptChanges不能继续,因为对象的键值与ObjectStateManager中的另一个对象冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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