Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoMapper: Mapping a collection of Object to a collection of strings
    primarykey
    data
    text
    <p>I need help with a special mapping with AutoMapper. I want to map a collection of objects to a collection of strings.</p> <p>So i have a Tag classd</p> <pre><code>public class Tag { public Guid Id { get; set; } public string Name {get; set; } } </code></pre> <p>Than in a model i have a IList of this class. Now i want to map the name's to a collection of strings.</p> <p>Thats how I define the mapping rule:</p> <pre><code>.ForMember(dest =&gt; dest.Tags, opt =&gt; opt.ResolveUsing&lt;TagNameResolver&gt;()) </code></pre> <p>And here is my ValueResolver:</p> <pre><code>protected override string ResolveCore(Tag source) { return source.Name; } </code></pre> <p>But u know.. it dont work ;-) So maybe someone know how to do it right and can help me.</p> <p>thx alot</p> <p>Jan</p> <p>Sooo.. u wanted more details.. here u get it.. but i have shorten it ;)</p> <p>So the Model:</p> <pre><code>public class Artocle { public Guid Id { get; set; } public string Title {get; set; } public string Text { get; set; } public IList&lt;Tag&gt; Tags { get; set; } } </code></pre> <p>And the Tag model u can see above.</p> <p>I want to map it to a ArticleView... i need the tag model only for some business context, not for tthe output.</p> <p>So here is the ViewModel i need to map to:</p> <pre><code>public class ArticleView { public Guid Id { get; set; } public string Title { get; set; } public string Text { get; set; } public IList&lt;string&gt; Tags { get; set; } // The mapping problem :-) } </code></pre> <p>So I have a BootStrapper for the mappings. My Mapping looks like this:</p> <pre><code>Mapper.CreateMap&lt;Article, ArticleView&gt;() .ForMember(dest =&gt; dest.Tags, opt =&gt; opt.ResolveUsing&lt;TagNameResolver&gt;()) </code></pre> <p>And I map it manuelly with a special method</p> <pre><code> public static ArticleView ConvertToArticleView(this Article article) { return Mapper.Map&lt;Article, ArticleView&gt;(article); } </code></pre>
    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.
    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