Remove ConcurrencyStamp updates on each migration

310 Views Asked by At

In my .NET (Core 5) project with EF Core (6.0.3), I have the Role class, defined like this:

public static readonly List<IdentityRoleClaim<string>> RolesClaims = GetRolesClaims();

[...]

private static List<IdentityRoleClaim<string>> GetRolesClaims()
{
    return new List<IdentityRoleClaim<string>>
    {
        new() { Id = 1, RoleId = "admin", ClaimType = ClaimTypes.Role, ClaimValue = "admin" }
    };
}

[...]

public class RoleClaimConfiguration : IEntityTypeConfiguration<IdentityRoleClaim<string>>
{
    public void Configure(EntityTypeBuilder<IdentityRoleClaim<string>> builder)
    {
        builder.HasData(Defaults.RolesClaims);
    }
}

The problem is that for every migration updates its ConcurrencyStamp in the Up and Down generated methods.

    migrationBuilder.UpdateData(
        schema: "dbo",
        table: "Roles",
        keyColumn: "Id",
        keyValue: "admin",
        column: "ConcurrencyStamp",
        value: "1e0c5e0e-a1a5-4131-9467-5df4b387b48f");

Is there a way to get rid of this noisy update?

0

There are 0 best solutions below