Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate DTO with deep object graph

I am writing a smart client WPF application using MVVM that communicates with a WCF service layer containing the business logic and domain objects that uses NHibernate to manage persistence. We are in control of both sides of the wire.

Currently, I am working on creating a screen to Edit Product Details it has a tab control with each tab representing some aspect of the Product such as Main Details, Product Class, Container Type and so on. In the end, there will probably be at least 5 of these tabs.

Up to now I have been working on transforming simple domain objects to DTOs using SetResultTransformer and this has been working quite nicely.

Now that I am getting to a more complicated object I am getting a bit stuck. I would like to return a DTO to be displayed that contains the Main Product details, categories and classes. As far as categories and classes are concerned I would not want to return every single property of the domain object.

Questions:
1) How do people go about creating a DTO where there are several one to many collections to return as in this example?
2) Is there any concerns about the DTO becoming too large?
3) When sending the DTO back to the back end is it better to send the same type of DTO with the updated values or some other more command oriented DTO?

Thanks for any help

Alex

like image 409
11 revs Avatar asked Jan 20 '26 23:01

11 revs


2 Answers

We are currently using pretty big DTOs and it is working pretty fine. NHibernate is doing a lot of lazy loading, so this helps with big objects.

We are using bags for one to many relations, they are lazy loaded and are working pretty well.

Depending on the type of application lazy loading can be a bit of a problem. We had some problems with our rich client application with big DTOs but with some planning and a sound architecture it works pretty well.

I don't know if large DTOs are really a problem with NHibernate, but so far we don't have got any problems.

We are sending the whole object back and forth and it is doing well. NHibernate updates just the changed fields and this is really nice.

I wouldn't serialize the NHIbernate objects over web services or something like that (I don't know the WCF service layer and how it communicates with your application). If I am transferring data through web services I am generating new data objects and fill them accoringly, transfer them back and forth and update the NHibernate objects with those.

like image 196
bernhardrusch Avatar answered Jan 23 '26 11:01

bernhardrusch


Have you tried Automapper? I do all my DTO mappings with Automapper and it works like a charm. Have a look at automapper. I'm sure you'll like it.

like image 32
zszep Avatar answered Jan 23 '26 11:01

zszep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!