1

I guess this has been asked before here , but I'm still confused about the correct approach to be taken.

I have a WPF client application which talks to a WCF service to retrieve data. On the Service side , I have a large entity ( around 25 properties) and I have three forms in my client app . On each form, I need the facility to edit certain properties of my domain entity. I do not want to return the large entity through the service as I need just 3-4 of its properties on each form. Hence I have created three DTOs ( we are using AutoMapper) , one for each screen. The service returns DTOs and this works very fine as far as the retrieval goes.

My question is how do I persist my DTOs. We are using NHibernate in the service layer. If I pass my partial DTOs to the service to persist , I would need to reload my large entity every time to perform the update.

Is this the only way to handle this scenario ?

What other options do I have if I need to display partial views of one single entity on the UI .. besides sending across the whole entity over the wire ..or creating three DTOs?

Thanks.

Community
  • 1
  • 1
Sennin
  • 1,001
  • 2
  • 10
  • 17

1 Answers1

1

Using NHibernate in the service layer it is logical that you will need to either:

a) load the entity during an update operation at the service, modify the required properties and then commit your transaction, or

b) if you have the object already available at the service (but not associated with the NHibernate session) then you can modify the required properties, call session.Update(obj) to reassociate the object with the session and then commit your transaction.

We use the first approach regularly where we have hundreds of different entities in our model. We pass specialised command request objects from client to server and then our service layer is responsible for performing the work specified in the command requests.

Alternatively you could formulate a HQL query as outlined here. But this will quickly get pretty ugly and difficult to maintain.

Community
  • 1
  • 1
Phil Degenhardt
  • 7,215
  • 3
  • 35
  • 46