Question

I know, I know. Why would anyone want to do that? The application already audits changes to data but now the business wants to audit all reads as well (without a convincing user story, I have to say). I have given them all the arguments against, but they insist.

So does EF/DbContext provide an extension point that would be suitable for intercepting all records returned from the database and writing an entry in an audit trail? Or is there another sensible way of doing this?

Was it helpful?

Solution

You could use the ObjectContext.ObjectMaterialized. MSDN snippet:

Occurs when a new entity object is created from data in the data source as part of a query or load operation.

This event is raised after all scalar, complex, and reference properties have been set on an object, but before collections are loaded. If an object with the same key value exists in the object context, the Entity Framework will not recreate the object and this event will not be raised.

But this would only track items read from Db through your EF implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top