I have two classes:
public class CustomerDTO
{
public string Name {get;set;}
public List<Order> Orders {get;set;}
}
public class OrderDTO
{
public string Name {get;set;}
public string Description {get;set;}
public decimal Cost{get;set;}
}
I am using AutoMapper for .NET 3.5 and currently doing the following in my Application_StartUp:
Mapper.CreateMap<Customer, CustomerDTO>();
Mapper.CreateMap<Order,OrderDTO>();
This is a simplified example as I named my DTO properties different than my entity properties, so I used ForMember, but I am unclear on how to map Orders to Customer:
I tried:
Mapper.CreateMap<Customer, CustomerDTO()
.ForMember(dest => dest.Orders, opt=> opt.MapFrom(src=>src.Orders));
but it does not find src.Orders
.
If I do indeed need to have both CreateMap
statements, does AutoMapper
"automatically" link the objects Customer
to Orders
?
orders
not anOrders
property. Is that just a typo in the posting? If it is as posted than that would be an issue, property names are case sensitive. – pstrjdsMapper.Map(cust, custDTO)
– Justin PihonyListMOrdersDTO> Orders {get;set};
?? – MethodManOrdem
andCustumer
classes? Maybe the type of Orders properties isn't the same. – fhelwanger