Data Transfer Objects and Change Tracking

Posts   
 
    
TopDog74
User
Posts: 40
Joined: 27-Apr-2012
# Posted on: 29-Jan-2015 18:21:01   

Hi,

I have a WCF service sitting on top of my LLBLGen Data Model. All the Entities are being mapped to Data Transfer Objects (using AutoMapper) as i would like the client to have no knowledge of the persistence mechanism behind the Service. So every service method returns a Data Transfer Object type.

At the moment when i 'Save' an Entity, i map the contract to an entity, and check if the primary key value is set or not, and manually set the .IsNew method on the Entity to true or false depending on PK value existence.

Also, when an update is required all properties are being updated, rather than just the properties that may have actually just changed.

What are the common ways to approach change tracking with this kind of setup?

Ideally I'd like to keep the WCF service with the simple DTO's but also ensure that when i 'Update' an Entity that only the changed properties get saved.

I think in NHibernate you can map the contract back to an entity and 'Merge' it into a data context. Does something like this exist in LLBLGen?

Thanks for your help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jan-2015 06:21:40   

TopDog74 wrote:

What are the common ways to approach change tracking with this kind of setup?

Ideally I'd like to keep the WCF service with the simple DTO's but also ensure that when i 'Update' an Entity that only the changed properties get saved.

AFAIK, when a DTO is sent to your web method, you should fetch the entity then set all the fields from the DTO to the entity, then save the entity, that way, only the updated fields are sent to the DB, this is also a good place to know whether the entity is new or not.

TopDog74 wrote:

I think in NHibernate you can map the contract back to an entity and 'Merge' it into a data context. Does something like this exist in LLBLGen?

What do you mean by 'context' and How does it NH?

This scenario is similar to MVC, where the view doesn't know about changes, it only render fields, and send them back to the controller, and at that point the controller doesn't know the entity state, it only know the fields that the view sent, you need an extra step (fetch) to recover the entity state.

David Elizondo | LLBLGen Support Team