Ocelot20
Ocelot20

Reputation: 10800

How to detect individual property changes for detached entities on update?

We are making use of EF change tracking in order to fire certain events. For example, if a person entity has an e-mail address change, we can send an e-mail to an administrator or something of that nature.

I'm wondering if there's an easy way to call something like CheckForChangesOnAttach(entity) that would query the db for the current data and compare with the detached entity to set certain properties as updated. Seems like something that shouldn't be too hard to do myself other than attaching large graphs of detached entities, which is why I'm wondering if there's something like that built in (we're using code first, btw).

Our system doesn't do much with detached entities, so 99% of the time we wouldn't need something like that, so I'm not too concerned about performance.

Upvotes: 1

Views: 768

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

Yes there is such option for single entity (you must load the entity by key and call ApplyCurrentValues on its ObjectSet - it will push new values from detached entity to attached one) but there is no option for object graphs - you must roll your own solution for object graphs.

Upvotes: 2

Related Questions