Closed scattered-code closed 3 years ago
Found a few solutions and asking the RavenDB team for guidance. Posting here for reference https://groups.google.com/g/ravendb/c/6bdDgEp313E
Thanks for the heads up. By all means, submit a PR and I'd be glad to merge it.
getting the current database from the session seems to be tricky.
This I don't understand. DbSession.Advanced.DocumentStore
is the database for the session. What am I missing?
I meant getting the name of the database the DbSession object is pointing to isn't possible through the interface since it's not exposed (DbSession.DatabaseName). I dug deeper into ravendb's code and it's available on the AsyncDocumentStore object, just not on the interface. I'll run a few more tests and submit a PR
DbSession.Advanced.DocumentStore points to the document store directly, and looses track of the session since the operations get executed against the document store, so it defaults to using the default database.
Thanks
If targeting a different database in the session other than the default database the store is initialized with, documents correctly go to the database configured in the IAsyncSession, however, Compare Exchange values go to the default database configured on the store. Under most cases they would be the same, but in my case I'm building a multi-tenant application in which I store users in separate databases at runtime.
https://github.com/ops-ai/BeyondAuth/blob/b35d86d6451edba74b03bad1b55b40a6e87332a2/src/Authentication/Startup.cs#L328
Part of the fix is simple, just adding .ForDatabase here: https://github.com/JudahGabriel/RavenDB.Identity/blob/c354b85ae7acbf0716c9cc056391ba4e0afb80e7/RavenDB.Identity/UserStore.cs#L806
However, getting the current database from the session seems to be tricky. Happy to create a PR once I figure it out if you're interested