Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoMapper - how to choose not to perform "inner" maps?
    primarykey
    data
    text
    <p>I have a weird case and I'm pretty new to AutoMapper and I can't understand what's happening.</p> <p>I have two classes</p> <pre><code>public class Person { public List&lt;Friend&gt; Friends {get;set;} } public class PersonView : Person { public new List&lt;FriendView&gt; Friends {get;set;} } </code></pre> <p>and the map</p> <pre><code>Mapper.CreateMap&lt;Person, PersonView&gt;().ForMember(d =&gt; d.Friends, o =&gt; o.ResolveUsing&lt;FriendViewResolver&gt;().FromMember(s =&gt; s.Friends)); </code></pre> <p>but, I also have this map, which has its own mapping:</p> <pre><code>Mapper.CreateMap&lt;Friend, FriendView&gt;().ForMember(/* a lot of stuff */); </code></pre> <p>Now, Inside FriendViewResolver - I'm calling <code>Mapper.Map&lt;Friend, FriendView&gt;()</code> for each of the friends. But for some reason after it runs, some of the properties get lost and from stepping over the code, it seems AutoMapper does a second pass on the list.</p> <p>I want to have the <code>FriendViewResolver</code> run on the list, because it is doing recursive stuff with the entire collection of <code>Friends</code>, but I don't understand why AM does a second pass if there's a resolver rule for the member.</p> <p>I really hope it makes sense.</p> <p>EDIT: the problem happens when I run <code>Mapper.Map&lt;Person, PersonView&gt;();</code>, I see it runs <code>FriendViewResolver</code> and has correct result, but next step in the debugger runs the maps again and messes up the already mapped objects.</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