Note that there are some explanatory texts on larger screens.

plurals
  1. POSelf Tracking Entities - AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager
    primarykey
    data
    text
    <p>I've been stuck with this problem for over a week now. Hopefully some one can point me in the right direction.</p> <p>I start with a brief description of my schema.</p> <p>Asset 1--->1 Address *-->1 Area *-->1 Region *-->1 Country</p> <p>Package 1-->* Asset</p> <p>Using Self Tracking Entity (STE) + WCF.</p> <p>Steps:</p> <ol> <li>Call data store for a list of assets.</li> <li>Call data store for a list of packages.</li> <li>User selects a package and assign some assets to it.</li> <li>Save package.</li> </ol> <p>In step 2, the call uses eager loading of Addresses.</p> <pre><code>from p in context.Assets.Include("Address.Area.Region.Country") </code></pre> <p>This is the error when attempting to call</p> <pre><code>context.Packages.ApplyChanges(package) </code></pre> <blockquote> <p>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.</p> </blockquote> <p><strong>EDIT</strong></p> <p>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 <a href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a15a2276-b9d5-4e77-bdf7-545d745bc590" rel="nofollow noreferrer">here</a>. Here is my question.</p> <blockquote> <p>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.</p> </blockquote> <p>Here are my constrains:</p> <ol> <li>I must use the navigational collection because it affect the UI.</li> <li>I cannot pre-fetch all entities that will be involved because the data set is simply too large.</li> <li>I must be able to take snap-shots of the entity at anytime in order to keep a history and use it to "undo" any changes.</li> </ol> <p>I am aware of the possible solutions suggested by <strong>Diego B Vega</strong>, but those are not options i can use for my solution. Has anyone any other ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload