Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging changes through Entity Framework

Can anyone direct me to a good strategy for implementing change tracking in my Entity Framework model?

I have around 20 entities to track changes on (accessed via facades / unit of work) and I need to be able to display who changed what when on displaying the record in the UI.

I know there's Context.OnSavingChanges (or whatever it's called) but I'd probably want to access the changes in queries like context.MyEntity.ChangeLog

Must I create a ChangeLog entity, add associations to all the entities or is there a better via via savingchanges?

Richard

P.s. Have a great weekend!

like image 893
Richard Avatar asked Jan 22 '26 18:01

Richard


1 Answers

Entity framework is ORM = API responsible for persistence and loading from database. What you persist or load is completely up to you so if you want change tracking you must to code it.

The most common approach is indeed using OnSavingChanges or overriding SaveChanges because you are usually saving changed executed by single user.

like image 112
Ladislav Mrnka Avatar answered Jan 25 '26 06:01

Ladislav Mrnka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!