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?
For users and roles, add an additional, not auto-partitioned collection to your DocumentDb
done.Fork this project and add the required code to support partitioning for your specific scenario
fork project for few methods? But even if I do this, how can I pass the partition key on role manager queries? – Anthony Minchenko Dec 4 '20 at 18:00new FeedOptions { EnableCrossPartitionQuery = true }
to the line: github.com/codekoenig/AspNetCore.Identity.DocumentDb/blob/…. – Jim Xu Dec 7 '20 at 2:31