开发者

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 associ开发者_如何学Pythonations to all the entities or is there a better via via savingchanges?

Richard

P.s. Have a great weekend!


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.


An old question but for anyone looking for auditing changes on EF >= 6 or EF Core, I worked on an open source library Audit.EntityFramework you could try.


See FrameLog, which is an open source library I wrote for this purpose. You call it from SaveChanges and it deals with the rest, including giving you a strongly-typed API for querying the logs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜