c# - ConfigureAutomapper to map contents of collection-property, but use destination collection object -
i have class
class { public a() { collectionprop = new list<b>(); } public icollection<b> collectionprop {get; private set;} }
lets want map -> a, cloning mechanism, dont want automapper attempt create collectionprop, should use collectionprop exists in destination object (created constructor), clone 'b' objects new instance of a.
how do this.. far have:
mapper.createmap<a, a>() .formember(dest => dest.collectionprop, opt => opt.mapfrom(e => e.collectionprop));
which appears use collectionprop newly created object, not filling elements.
what missing?
thanks
this 1 worked me
mapper.createmap<a, a>() .convertusing((s) => { var d = new a(); d.collectionprop.addrange(s.collectionprop); return d; });
ok. 1 clones bs
mapper.createmap<b,b>(); mapper.createmap<a, a>() .convertusing(s => { var d = new a(); s.collectionprop.tolist() .foreach(b => d.collectionprop.add(mapper.map<b,b>(b))); return d; });
Comments
Post a Comment