c# - Automapping - for IEnumerable map multiple properties with different name -
i have 2 class say:
public class sourcedata { public string sourcecode { get; set; } public string sourcename { get; set; } }
and
public class destdata { public string code { get; set; } public string destname { get; set; } }
i try map ienumerable of sourcedata destdata, not working
i try with
automapper.mapper.createmap<ienumerable<sourcedata >, ienumerable<destdata>>()
both classes have field different names. automapper won't pick them automatically. need explicitly tell how map fields in both classes. this.
mapper.createmap<sourcedata, destdata>() .formember(dest => dest.destname, => a.mapfrom(src => src.sourcename)) .formember(dest => dest.code, => a.mapfrom(src => src.sourcecode))
note creating map between types not between collections of types automapper automatically handle collections. next use following map:
var destlist= mapper.map<list<destdata>>(sourcelist);
or
mapper.map<list<sourcedata>, list<destdata>>(sourcelist, destlist);
depending on situation.
Comments
Post a Comment