带有EF Core和CosmosDB的ASP.Net Core-IdentityRole问题 [英] ASP.Net Core with EF Core and CosmosDB - IdentityRole issue
问题描述
我正在尝试将asp.net核心应用程序从使用Azure SQL数据库迁移到使用CosmosDB数据库.
I am trying to migrate my asp.net core application from using Azure SQL database to use CosmosDB database.
尝试使用以下错误消息创建集合时遇到问题:
Facing an issue when trying to create collections with the following error messages:
System.InvalidOperationException:'实体类型'IdentityRole'具有属性"ConcurrencyStamp"作为其并发令牌,但只有"_etag"支持.考虑使用'EntityTypeBuilder.UseETagConcurrency'.
System.InvalidOperationException: 'The entity type 'IdentityRole' has property 'ConcurrencyStamp' as its concurrency token, but only '_etag' is supported. Consider using 'EntityTypeBuilder.UseETagConcurrency'.'
我尝试了这些更改,但都没有解决问题.
I have tried these changes, none of them solve the issue.
- 我在构建模型时添加了
UseETagConcurrency
builder.Entity< IdentityRole>().ToContainer("Roles").UseETagConcurrency();
- 我从
IdentityRole
创建新的派生类,并添加了_etag
属性Role
模型
- I added
UseETagConcurrency
when building the modelbuilder.Entity<IdentityRole>().ToContainer("Roles").UseETagConcurrency();
- I create new derived class from
IdentityRole
, added_etag
property toRole
model
关于如何解决此问题的任何想法?
Any ideas on how to resolve this issue?
谢谢您的帮助.
推荐答案
想通了!问题是角色和角色;用户已经具有并发令牌,该令牌存储在属性"ConcurrencyStamp"中.因此,我们需要告诉EF这个属性是我们要用于Etag并发的属性.因此,不要使用 UseETagConcurrency()
,而是使用以下代码:
Figured it out! The issue is Role & User already have a concurrency token which is stored in the property 'ConcurrencyStamp'. So we need to tell EF that this property is what we want to use for the Etag concurrency. So instead of using UseETagConcurrency()
use the following:
builder.Property(d => d.ConcurrencyStamp)
.IsETagConcurrency();
这篇关于带有EF Core和CosmosDB的ASP.Net Core-IdentityRole问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!