Entity Framework + AutoMapper (сущность для DTO и DTO для сущности)

У меня есть некоторые проблемы с использованием EF с AutoMapper. знак равно

например :

У меня есть 2 связанных объекта (Клиенты и Заказы), и они являются классами DTO:


class CustomerDTO
{
   public string CustomerID {get;set;}
   public string CustomerName {get;set;}
   public IList< OrderDTO > Orders {get;set;}
}<p></p>

<p>class OrderDTO
{
   public string OrderID {get;set;}
   public string OrderDetails {get;set;}
   public CustomerDTO Customers {get;set;}
}</p>

<p>//when mapping Entity to DTO the code works
Customers cust = getCustomer(id);
Mapper.CreateMap< Customers, CustomerDTO >();
Mapper.CreateMap< Orders, OrderDTO >();
CustomerDTO custDTO = Mapper.Map(cust);</p>

//but when i try to map back from DTO to Entity it fails with AutoMapperMappingException. Mapper.Reset(); Mapper.CreateMap< CustomerDTO , Customers >(); Mapper.CreateMap< OrderDTO , Orders >(); Customers customerModel = Mapper.Map< CustomerDTO ,Customers >(custDTO); // exception is thrown here

Am I doing something wrong?

Thanks in Advance !

Ответы на вопрос(8)

Ваш ответ на вопрос