[Solved] AutoMapper convert from multiple sources

Bart Calixto Asks: AutoMapper convert from multiple sources
Let’s say I have two model classes:

Code:
public class People {
   public string FirstName {get;set;}
   public string LastName {get;set;}
}

Also have a class Phone:

Code:
public class Phone {
   public string Number {get;set;}
}

And I want to convert to a PeoplePhoneDto like this:

Code:
public class PeoplePhoneDto {
    public string FirstName {get;set;}
    public string LastName {get;set;}
    public string PhoneNumber {get;set;}
}

Let’s say in my controller I have:

Code:
var people = repository.GetPeople(1);
var phone = repository.GetPhone(4);

// normally, without automapper I would made
return new PeoplePhoneDto(people, phone) ;

I cannot seem to find any example for this scenario. Is this possible ?

Note: Example is not-real, just for this question.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, ten-tools.

 

_


(adsbygoogle = window.adsbygoogle || []).push({});