ASP.Net Core with EF Core and CosmosDB - IdentityRole issue

Viewed 1089

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.

  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?

Thank you for your assistance.

2 Answers
 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();
Related