Automapper map nested collection -
i'm new automapper, , struggling custom mapping working. i'm using 1.1 works .net 3.5.
essentially, want create list dto built using 1 subclass contained within list class of parent model.
below should better illustrate mean:
public class redcar { public string name{get;set;} public list<redcarpart> redcarparts(get;set;} } public class redcarpart { public string redcarserial{get;set;} public carpart carpart {get;set;} } public class carpart { public int partid {get;set;} public string description {get;set;} } public class cardto { public string name{get;set;} public list<carpartdto> carparts{get;set;} } public class carpartdto { public int partid {get;set;} public string description {get;set;} } i don't need information provided within redcarpart, , need list of carparts.
i know can replicate redcarpartdto, , ignore fields don't need, rather pass down client, feel better see if can map list of carparts.
i'm thinking must map from, i'm having trouble how i'm doing this:
mapper.createmap<redcar, cardto>() .formember(s => s.carparts, c => c.mapfrom(m => m.redcarparts)); mapper.createmap<redcarpart, carpartdto>() .formember(s => s.partid, c => c.mapfrom(m => m.carpart.partid)) .formember(s => s.description, c => c.mapfrom(m => m.carpart.description));
Comments
Post a Comment