c# - how get propertyField Mapped Relation (MapFrom) in Automapper -
i have sample code:
namespace automappercontracts { public interface ihavecustommappings { void createmappings(iconfiguration configuration); } } public class classa { public int id { get; set; } public string nametest { get; set; } public string familytest { get; set; } public icollection<classb> classbs { get; set; } } public class classb { public int id { get; set; } . . . public datetime dateinsert { get; set; } public int classaid { get; set; } public classa classa { get; set; } //other realation public int classcid { get; set; } public classc classc { get; set; } } public class classabviewmodel : ihavecustommappings { public int id { get; set; } public string name { get; set; } public string family { get; set; } public string fullname { get; set; } public string dateinsert { get; set; } public int classcid { get; set; } public string classcname { get; set; } public int classaid { get; set; } public void createmappings(iconfiguration configuration) { configuration.createmap<classb, classabviewmodel>() .formember(model => model.classcname, opt => opt.mapfrom(c => c.classc.name)) .formember(model => model.name, opt => opt.mapfrom(c => c.classa.nametest)) .formember(model => model.family, opt => opt.mapfrom(c => c.classa.familytest)) .formember(model => model.fullname, opt => opt.mapfrom(c => c.classa.nametest+ " " + c.classa.familytest)) } }
i mapped properties code:
typemap map = mapper.getalltypemaps().where(m => m.sourcetype.equals(destinationtype)).first(); ienumerable<propertymap> properties = map.getpropertymaps().where(p => p.destinationproperty.name.equals("fullname", stringcomparison.currentcultureignorecase));
i need more details
how fields name mapped --> name, or family or fullname automatically? means need property name of nametest, familytest use fullname
Comments
Post a Comment