0

If I map my Domain objects to linq Entities will I now not be able to track changes when saving my domain objects? So for any change in my model that i wish to make, once I map the object to linq entities for submission to db, all object values will be submitted to the db by linq since it it goes through a mapping first? Or would the object tracking here still be utilized?

zsharp
  • 13,656
  • 29
  • 86
  • 152

2 Answers2

1

Depends on the O/R mapper you're using. You're referring to entity framework which doesn't do any change tracking inside the entity and therefore it needs help from you when you re-attach an entity which previously was fetched from the db (so it knows it's not new).

Frans Bouma
  • 8,259
  • 1
  • 27
  • 28
  • linq to sql has tracking. But when i map domain back to the entity it considers everything changed even if it was not. how to tell entity its not a real change or vice versa? – zsharp Apr 21 '09 at 18:37
1

Here's an article from microsoft about CRUD operations in multi-tiered environments (similiar issues to your Domain mapping scenario).

Check out the Update - With Complete Entities for the way to do change tracking yourself.

There's another technique, where you attach the entity as unmodified, and then .Refresh() with Keep Current Values - replacing the original. This would allow you to Insert/Update/Do Nothing as appropriate at the cost of a database roundtrip.

Amy B
  • 108,202
  • 21
  • 135
  • 185