Automapper mapping 2 entities to a single class -


just wondering if possible:

say have viewmodel comparing old , new entity.

public class foocomparison { public string name {get;set;} public string oldname {get; set;} public int age {get; set;} public int oldage {get; set;} ... } 

i want load 2 instances of foo database , populate foocomparison details both instances.

for now, have mapper.createmap<foo, foocomparison>() populate name, age etc first entity - there easy way populate oldxxx properties second entity without looping , manually updating them?

my suggestion define mapping tuple<foo, foo> foocomparison:

mapper.createmap<tuple<foo, foo>, foocomparison>()     .convertusing(x => new foocomparison     {         name = x.item2.name,         oldname = x.item1.name,         age = x.item2.age,         oldage = x.item1.age,         ...     }); 

then use this:

foo oldfoo = ...; foo newfoo = ...; foocomparison comparison = mapper.map<foocomparison>(tuple.create(oldfoo, newfoo)); 

i appreciate loses "auto" part of automapper, big benefit getting using automapper mapping defined in 1 place in software, not auto part.

i have found way of mapping via tuple work well.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -