Why does checking for a role require a cross-partition query?

Viewed 140

On the azure portal, I created Cosmos DB (core (SQL) API), added a users container (partition key id) and roles (partition key name) there. Installed the CodeKoenig.AspNetCore.Identity.DocumentDb package. Then, when I try to determine whether a role exists in the database through the role manager, I get a DocumentClientException: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception. This is how I configured the identity service:

services.AddIdentity<Models.Entities.User, DocumentDbIdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
    .AddDocumentDbStores(options =>
    {
        options.Database = "forumdb";
        options.UserStoreDocumentCollection = "users";
        options.RoleStoreDocumentCollection = "roles";
    })
    .AddDefaultTokenProviders();

Code that throws an exception:

var roleManager = serviceProvider.GetRequiredService<RoleManager<DocumentDbIdentityRole>>();
roleManager.RoleExistsAsync(roleName).Result;

Models.Entities.User inherits from AspNetCore.Identity.DocumentDb.DocumentDbIdentityUser. I doubt there should be a сross partition request to check if a role exists. What did I do wrong or how to set x-ms-documentdb-query-enablecrosspartition to true for RoleManager requests?

0 Answers
Related