Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service exposing DTO or Entity

Tags:

wcf

wpf

model

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

like image 911
Mauro Destro Avatar asked Mar 16 '09 08:03

Mauro Destro


1 Answers

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.

like image 90
Marc Gravell Avatar answered Sep 30 '22 06:09

Marc Gravell