Reputation: 21
My ViewModel has a sequence of related entities like that:
Store.Package.Item
I am trying to ignore the last Item element on my path, when mapping from the viewmodel to the entity. That's my mapping:
CreateMap<Store, StoreViewModel>().ReverseMap().ForPath(s => s.Package.Item, opt => opt.Ignore());
The problem is that the entire Package element is being ignored, but I need to ignore just the Item property.
Could anyone help me on this?
Regards
Upvotes: 2
Views: 1291
Reputation: 11
You can add another mapping from the Package type into itself and ignore the item property
CreateMap<Store, StoreViewModel>().ReverseMap();
CreateMap<*PackageClass*, *PackageClass*>().ReverseMap()
.ForMember(s => s.Item, opt => opt.Ignore());
PackageClass is the type of the Store.Package property
Upvotes: 1
Reputation: 1
You could do something like this:¨
Mapper.Initialize(c=>
{
c.CreateMap<Store, StoreViewModel>().ReverseMap();//.ForPath(s => s.Package.Item, opt => opt.Ignore()));
c.CreateMap<Package, PackageViewModel>().ReverseMap().ForPath(s=> s.Item,opt=> opt.Ignore());
});
Upvotes: 0