Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoMapper, how to keep references between mapped objects?
    primarykey
    data
    text
    <p>I am using AutoMapper to convert a UI model to POCOs that I later serialize to XML using a DataContractSerializer in order to preserve the references between them.</p> <p>The problem comes that, when mapping, <strong>the references between those entities are lost</strong>.</p> <p>The UI classes reference each other, but the mapping process makes new instances for every reference, so the original relations are broken :(</p> <p>Let me explain:</p> <p>I have 2 entities of type Person</p> <pre><code> Person { List&lt;House&gt; OwnedHouses } </code></pre> <p>And these 2 objects</p> <p><strong>John</strong> who owns</p> <ul> <li><strong>House1</strong> </li> </ul> <p><strong>Will</strong> who also owns</p> <ul> <li><strong>House1</strong> </li> </ul> <p>When AutoMapper maps each Person correctly, but when it also maps House1 as two different instances!!</p> <p>So I have a two copies of House1. John owns his House1 (#1) and Will owns his House1 (#2).</p> <p>They are not linked anymore.</p> <p>Is there any way to keep the relations that originally existed?</p> <p>Thanks.</p> <p>EDITED: Actually what I have is this:</p> <p>A Document contains a list of ChildDocuments. Each ChildDocument has a list of Designables (Rectangles, Lines, Ellipses…) and a especial designable called ChildDocumentAdapter that contains itself ANOOTHER ChildDocument. This is the trouble, it can reference another ChildDocument.</p> <p><img src="https://i.stack.imgur.com/zfscZ.jpg" alt="The diagram"></p>
    singulars
    1. This table or related slice is empty.
    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.
    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