AutoMapper with IList <Item>

I have an article class with property

private IList<Tag> _tags;
public virtual IList<Tag> Tags
{
get{
if(_tags == null)
  _tags = TagService.GetTags(this);
return _tags;
}
}

Since there is no SET for tags, automapper will not set tags when matching with the viewmodel for viewing. Any ideas?

+3
source share
2 answers

Try using the UseDestinationValue option:

ForMember (dest => dest.Tags, opt => opt.UseDestinationValue ());

In the last DLL on the trunk, AutoMapper should pick up the members of the read-only list.

+4
source

You can ignore the property using:

ForMember(dest => dest.Tags, opt => opt.Ignore());
0
source

Source: https://habr.com/ru/post/1724610/


All Articles