0

Does the EF5 support object state tracking out of the box for disconnected entities or do we have to write our own implementation of it.

If so, are there any good reference examples out there?

Null Reference
  • 11,260
  • 40
  • 107
  • 184

1 Answers1

1

Self tracking entities (STEs) seem to be the thing you want. Ther used to be this template, but it seems Microsoft is not so fond of STEs anymore. They advise you to read this though. They explain here why.

LueTm
  • 2,366
  • 21
  • 31
  • But it doesn't track properties. If I'm doing an update, it will update every single column in my table – Null Reference Oct 24 '12 at 08:14
  • That's pretty much the opposite of *change tracking*. How do you know that `Password` has been modified? *Change tracking* would mean that EF knows it so that you don't have to mark properties as `Modified` manually. – Slauma Oct 25 '12 at 22:43
  • @Slauma It could have rescued him from using STEs :) – LueTm Oct 25 '12 at 23:11
  • An alternative rescue would be to answer the question in the title just with "No." :) – Slauma Oct 25 '12 at 23:22
  • But not when you want to use Code-First :) But seriously, I don't understand what they are saying under the second link. There is the Lerman/Miller approach to put an `EntityState` flag into the POCOs. This would be indeed client side change tracking, but it's not out-of-the-box and it requires to set and manage this flag on the client. They say "that's not an easy task, use the other approaches". The other approaches are WebAPI and WCF Data Services. How do they provide change tracking? The way I know is merging changes into the original which is "manual change detection", but not "tracking". – Slauma Oct 25 '12 at 23:36
  • For me all this feels like they want to have the cake and eat it too. They want slim POCOs but full fledged change tracking. And besides, if you're not coding something that must handle tons of updates a second, updating the whole entity doesn't kill you. – LueTm Oct 25 '12 at 23:39
  • But I see your point. I guess their point is, if you don't really really need it, use the WebAPI or WCF Data Services approach. But if you do, don't be surprised if the road's a little bumpy – LueTm Oct 25 '12 at 23:45
  • Updating the whole entity works as long as you only have scalar properties to update. As soon as relationship changes get involved (like adding, removing, changing items in child collections) it's getting hairy. I'm still using an approach like this for relationship updates in disconnected scenarios (http://stackoverflow.com/a/5540956/270591) which isn't really change "tracking" and far from being out-of-the-box but a lot of code to write instead. I don't think the alternatives have been improved with EF 5. – Slauma Oct 25 '12 at 23:54