nhibernate - C# Automapper conditional mapping -
i using nhibernate map elements 1 object another. however, 1 of elements in complex objects, needs have condition set in order destination object element have value set accordingly.
to explain in detail
mapper.createmap<oneobject, anotherobject>() .formember( destination => destination.complexelement, option => option.mapfrom(source=> source.value == enumvalue.tostring() ? new object( {id 123 }) : new object ({ id 567 }))
so, can see want set nested object on destination object based upon value source object create object , save destination element. example code above have tried, throwing error saying can't use string on lambda expression.
does know how can set object based upon condition?
thanks
i think work you. unfortunately based on automapper 6.1.1. hope can use version. because didn't know class structure, created simple test classes, should abled transfer sample scenario.
oneobject oo = new oneobject(); oo.value = "b"; testenum enumvalue = testenum.a; mapper.initialize(a => a.createmap<oneobject, anotherobject>() .formember( destination => destination.complexelement, option => option.mapfrom(source => source.value == enumvalue.tostring() ? 123 : 567))); anotherobject ao = mapper.map<oneobject, anotherobject>(oo);
test classes , enum
class oneobject { public string value { get; set; } } class anotherobject { public object complexelement { get; set; } } enum testenum { a, b, c }
Comments
Post a Comment