public class Person {
public string Name { get; set; }
public int Age { get; set; }
}
public class Planet {
public int Id { get; set; }
public string Name { get; set; }
}
public class PersonView {
public string Name { get; set; }
public int Age { get; set; }
public int PlanetId { get; set; }
I have a Collection of People:
IEnumerable<Person> people = new IEnumerable<Person>();
And one Planet:
Planet ours = new Planet(){
Id=1,
Name="Earth"
}
Input would be:
[
{
"Name": "George",
"Age": 21
},
{
"Name": "Lisa",
"Age": 24
},
{
"Name": "George",
"Age": 18
}
]
and
{
"Id":1,
"Name":"Earth"
}
With mapping something like this:
IEnumerable<PersonView> people =
mapper.Map<Person, PersonView>(people)
.Map<Planet, PersonView>(people);
Output would be:
[
{
"Name": "George",
"Age": 21,
"PlanetId": 1
},
{
"Name": "Lisa",
"Age": 24,
"PlanetId": 1
},
{
"Name": "George",
"Age": 18,
"PlanetId": 1
}
]
I want to map the PersonView (destination) type with the two source types People and Planet, is this possible?
I know how to Map two sources to one destination --> Automapper - Multi object source and one destination
But I don't know how I can do this when there is one object and one Collection to one Collection.