Search code examples
ravendb

How can I override SaveChanges method in RavenDB?


Is there a way to modify behavior of SaveChanges method in RavenDB? When I use EF Core, I always override that method in my DbContext to provide additional logic, such as setting audit fields (CreatedBy, ModifiedBy etc.). In RavenDB however, I do not inherit from DocumentSession anywhere.


Solution

  • Checkout the OnBeforeStore event
    in: https://ravendb.net/docs/article-page/5.2/Csharp/client-api/session/how-to/subscribe-to-events.


    You can perform custom actions on any entity right before it is stored on the server.