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:
如果我创建一个将实体转换为DTO的方法,我将遇到一些循环调用方法(可能由模型中的错误引起),例如:
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...
Product类有一个属性Supplier,它指向包含List属性的Supplier类,其中包含所有提供的产品。因此,如果我创建一个返回ProductDTO类的GetProductDTO(Product entity)方法,我将不得不调用GetSupplierDTO(Supplier entity) )对于每个产品,但最后一个方法必须为提供的产品列表中的每个产品调用GetProductDTO ...
In summary, i'm searching for a pattern or best practice to create a EntityModel -> WCF Service -> Prism WPF application.
总之,我正在寻找创建EntityModel - > WCF服务 - > Prism WPF应用程序的模式或最佳实践。
Thanks
谢谢
1 个解决方案
#1
5
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.
通常,对于DTO目的,您可能只是选择不序列化任何“父”属性。通常,您会看到DTO没有导航属性,除了严格关联的数据(例如,order-header => order-detail,但您没有order-header => customer - 只是客户的密钥;您将获取客户单独)。使用这种方法,有一个单向路径来序列化/反序列化任何图形,它应该工作正常。
#1
5
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.
通常,对于DTO目的,您可能只是选择不序列化任何“父”属性。通常,您会看到DTO没有导航属性,除了严格关联的数据(例如,order-header => order-detail,但您没有order-header => customer - 只是客户的密钥;您将获取客户单独)。使用这种方法,有一个单向路径来序列化/反序列化任何图形,它应该工作正常。