Skip to content

Cosmos db manual session token management #36504

Description

@JoasE

What problem are you trying to solve?

When working with azure cosmos db in the context of a user, the session token is required for read your own write guarantees (or session consistency) to work.
https://learn.microsoft.com/en-us/azure/cosmos-db/consistency-levels#session-consistency
I could not find any documentation on setting or retrieving the session token in a dbcontext.

Describe the solution you'd like

Possibly you could define extension methods (or extension members when those are released) on the DbContext type to get and set the session token on the DbContext before any reads or writes.

myDbContext.SetSessionToken(sessionToken);
var result = await myDbContext.Documents.Where(x => x.Id == id).FirstOrDefaultAsync();

result.Property = "changes";
await myDbContext.SaveChangesAsync();
sessionToken = myDbContext.GetSessionToken();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions