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: '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
when building the model
builder.Entity<IdentityRole>().ToContainer("Roles").UseETagConcurrency();
IdentityRole
, added _etag
property to Role
modelAny ideas on how to resolve this issue?
Thank you for your assistance.
One of the biggest reasons not to use Entity Framework Core is that your application needs the fastest possible data access. Some applications do a lot of heavy data operations with very high-performance demands, but usually business applications don't have that high of a performance demand.
Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.
EF Core 6.0 performance is now 70% faster on the industry-standard TechEmpower Fortunes benchmark, compared to 5.0. This is the full-stack perf improvement, including improvements in the benchmark code, the . NET runtime, etc. EF Core 6.0 itself is 31% faster executing queries.
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<IdentityRole>()
.Property(b => b.ConcurrencyStamp)
.IsETagConcurrency();
builder.Entity<ApplicationUser>() // ApplicationUser mean the Identity user 'ApplicationUser : IdentityUser'
.Property(b => b.ConcurrencyStamp)
.IsETagConcurrency();
}
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With