0

I've used Entity Framework 4.0 POCO entities for persistence layer in the current project.

I've used DTO's to send the data from Service Layer to UI Layer. Repositories and inside of Service Layer have used POCO.

There is a Mapping Layer to map (DTO to Domain(POCO) and (Domain(POCO) to DTO). At the moment, we manually track the changes.

For example, If entity id is zero we assume that entity is a new one and if not entity is an update.

Is there any way to achieve this other than implementing IsTransient(New), IsDirty(Update) or IsDeleted(Delete) properties manually in Entity Framework 4.0?

marvelTracker
  • 4,691
  • 3
  • 37
  • 49

1 Answers1

2

If you use your custom DTO you must always implement your own change tracking.

EF 4 offers only self tracking entities but that would require you to use these entities directly instead of DTOs and they have some other disadvantages.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Thanks. What are the areas/practices that we need to be taken care when we try to create custom tracking system ? – marvelTracker Sep 28 '11 at 06:07
  • It depends how complex do you want your tracking. Do you want to track state of entity or property? Do you want to track state of relations in object graph? You can have simple change tracking as you described or you can have some very complex implementation of change set offering features like `DataSet`. – Ladislav Mrnka Sep 28 '11 at 10:06
  • Actually, I need a tracking system for object graph. Even though, I implement a custom tracking system, Does it valid for WCF services? – marvelTracker Sep 28 '11 at 10:41
  • Yes but change tracking will become part of your data contracts and correct functionality of your service will be dependent on change tracking information passed from your clients. – Ladislav Mrnka Sep 28 '11 at 10:55
  • yup. I could agree with the contract among clients.However, Is it a good idea to give the control of persistence Logics to clients or that responsibility of the persistence, should handle by the Service ? At the same time, How can we navigate object graph for changers ? – marvelTracker Sep 28 '11 at 11:29
  • You must have additional datastructures holding information about deleted or added relations. Persistence rules should be on the service but that requires abandoning all change tracking on client side and doing merge on the service (load actual graph from DB and merge incoming graph from the client to the actual one) - that is the way I prefer. – Ladislav Mrnka Sep 28 '11 at 11:36
  • Thanks again and this will help us to design the tracking – marvelTracker Sep 29 '11 at 03:05