auto mapping properties from two classes with third class using automapper

205 Views Asked by At

I have two classes, say ClassA and ClassB, and I want to map them with ClassC. How can I do it?

ClassA has only 1 property and ClassB has 5 properties. ClassC has 6 properties.

Situation is something as below:

Public ClassC MapRequest(classA id, ClassB someProperties){
    _mapper.Map<ClassC>(id);
    _mapper.Map<Classc>(someProperties);

    retrun type of ClassC;
}
1

There are 1 best solutions below

0
On

There is overload of Map method available.

var objClassC = _mapper.Map<ClassA, ClassC>(id);

// You need to pass above instance to next call.
_mapper.Map<ClassB, ClassC>(someProperties, objClassC );

Hope this helps.