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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With