带有 EF Core 和 CosmosDB 的 ASP.Net Core - IdentityRole 问题 [英] ASP.Net Core with EF Core and CosmosDB - IdentityRole issue

查看:33
本文介绍了带有 EF Core 和 CosmosDB 的 ASP.Net Core - IdentityRole 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 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.

  1. 我在构建模型时添加了 UseETagConcurrencybuilder.Entity().ToContainer(Roles").UseETagConcurrency();
  2. 我从 IdentityRole 创建了新的派生类,添加了 _etagRole 模型的属性
  1. I added UseETagConcurrency when building the model builder.Entity<IdentityRole>().ToContainer("Roles").UseETagConcurrency();
  2. I create new derived class from IdentityRole, added _etag property to Role 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆