I have somewhat some issue.
In EF Core you can use interceptors, here's some sample code that may be of use:
using System.Data.Common;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DiagnosticAdapter;
public class CommandListener
{
[DiagnosticName("Microsoft.EntityFrameworkCore.Database.Command.CommandExecuting")]
public void OnCommandExecuting(DbCommand command, DbCommandMethod executeMethod, Guid commandId, Guid connectionId, bool async, DateTimeOffset startTime)
{
//call security or other methods here.
}
[DiagnosticName("Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted")]
public void OnCommandExecuted(object result, bool async)
{
//call security or other methods here.
}
}
In the constructor of your repository you do the hooking
var listener = _context.GetService<DiagnosticSource>();
(listener as DiagnosticListener).SubscribeWithAdapter(new CommandListener());
Now when you query your dbContext e.g.:
_context.employees.Where(...
Then before this query is returned the above methods OnCommandExecuting and OnCommandExecuted are executed.
So you can somewhat imitate the override of SaveChanges in EF Core.
However one important thing to note is that the return result set from the query is not accessible in the OnCommandExecuting and OnCommandExecuted methods.