Blog Stats
  • Posts - 171
  • Articles - 1
  • Comments - 207
  • Trackbacks - 5

 

AutoMapper, EFPocoGenerator, EntityFramework and associations

Sto usando per ora con un certo “piacere” AutoMapper per mappare tutte le entities di EF nel mio layer di DTO.

Il DTO lo creo utilizzando EFPocoGenerator.

EF genera nelle entities anche le proprietà relative alle relazioni 1—Molti, quindi se per esempio User contiene una foreign key di tipo UserStatus, la entity UserStatus conterrà a sua volta una prorietà List<User>(la troveremo nelle Navigation Properties dell’ edmx).

Il problema è il seguente: se cerco di mappare con AutoMapper una query linq to entities che mi ritorni Users e UserStatus, il metodo Map di AutoMapper va in stack overflow.
Infatti cercherà di mappare in ordine: le proprietà di User, UserStatus, List<User> in UserStatus, UserStatus, etc…. in ricorsione infinita.

Per farla breve e veloce, ho optato per una scelta di questo tipo: non mi serve avere nel mio DTO la mappatura delle relazioni 1 a Molti, che eventualmente inserirò a mano quando necessario nelle partial class relativi ai DTO autogenerati.

Ho quindi fatto una piccola modifica al codice di EFPocoGenerator per impedire la generazione di tali proprietà e tutto ora funziona correttamente.


Feedback

# re: AutoMapper, EFPocoGenerator, EntityFramework and associations

Gravatar Luke,
Its good but where is the working example?
How u fix it ?
What did u change in Poco Adapter? 05/10/2009 13.15 | None

Comments have been closed on this topic.
 

 

Copyright © Luca Mauri