Andrej Kaurin
Andrej Kaurin

Reputation: 11642

AutoMapper with IList<Item>

I have 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 mapping from viewmodel to view. Any ideas?

Upvotes: 3

Views: 1035

Answers (2)

BitKFu
BitKFu

Reputation: 3697

You can Ignore then property using:

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

Upvotes: 0

Jimmy Bogard
Jimmy Bogard

Reputation: 26785

Try using the UseDestinationValue option:

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

In the latest DLL on the trunk, AutoMapper should pick up readonly list-type members.

Upvotes: 4

Related Questions