views:

50

answers:

1

Hi all,

I was wondering if there was a generic way to log changes/additions/deletions for each object using EF 4.0. I know you can override the int SaveChanges(SaveOptions options) method but i'm not sure what i should put in there.

Thanks

A: 

You can handle SavingChanges event on your context and use context.ObjectStateManager.GetObjectStateEntries(EntityState) to get information about changes. This method returns enumeration of ObjectStateEntry which contains information about changes.

Ladislav Mrnka
How would i access a generated id for a new insert within the savingchanges method?
zSysop
You can't get Id in SaveChanges, because Id is generated by database AFTER SaveChanges.
Tomas Voracek