tags:

views:

936

answers:

1

I have read questions and answers about this topic but I still have some question without answer.

If I create a method to convert Entity to DTO i'll run into some circular calling methods (probably caused by errors in Model), for example:

Product class has a property Supplier that point to a Supplier class that contains a List property with all the products supplied.. So if i create a GetProductDTO(Product entity) method that return a ProductDTO class i'll have to call GetSupplierDTO(Supplier entity) for each product, but this last method must call GetProductDTO for every product in the list of products supplied...

In summary, i'm searching for a pattern or best practice to create a EntityModel -> WCF Service -> Prism WPF application.

Thanks

+3  A: 

In general, for DTO purposes you might simply choose not to serialize any "parent" properties. Often, you see DTO with no navigation properties except for strictly associated data (for example, order-header => order-detail, but you wouldn't have order-header => customer - just the customer's key; you'd fetch the customer separately). With this approach, there is a unidirectional path to serialize/deserialize any graph, and it should work fine.

Marc Gravell
Ok, this can be the rapid solution... next in the client I have to re-create the graph? So in each side i have to convert EF->DTO and DTO->EF ?
Mauro Destro
Yes. That's what you have to do.
John Saunders
Damn, it's not the answer i was waiting for... :-)
Mauro Destro