-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Description
When Mapping a class with multiple collections (Phones and Address), I got a System.Reflection.TargetException - Object does not match target type.
Am I missing something?
public class Address
{
public int AddressID { get; set; }
public string Street { get; set; }
}
public class Phone
{
public int PhoneID { get; set; }
public string Number { get; set; }
}
public class Person
{
public int PersonID { get; set; }
public string Name { get; set; }
public Address[] Address { get; set; }
public Phone[] Phones { get; set; }
}
public class Program
{
static void Main(string[] args)
{
var data = new List<Dictionary<string, object>>();
data.Add(new Dictionary<string, object>()
{
{"PersonID", 1},
{"Name", "Client 1"},
{"Address_AddressID", 1},
{"Address_Street", "Line 1"},
{"Phones_PhoneID", 1},
{"Phones_Number", "555-555-5555"}
});
data.Add(new Dictionary<string, object>()
{
{"PersonID", 1},
{"Name", "Client 1"},
{"Address_AddressID", 1},
{"Address_Street", "Line 1"},
{"Phones_PhoneID", 2},
{"Phones_Number", "444-444-4444"}
});
AutoMapper.Configuration.AddIdentifier(Type.GetType("Address"), "AddressID");
AutoMapper.Configuration.AddIdentifier(Type.GetType("Phone"), "PhoneID");
var person = AutoMapper.Map<Person>(data);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels