Skip to content

EF Core spam: AdminUsersView.Roles value converter has no value comparer #336

Description

@hhvrc

Our logs are getting flooded with this warning on basically every startup and query, across all the gateways and the API:

The property 'AdminUsersView.Roles' is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly.

It's not breaking anything, but it's noise and it makes the real warnings harder to spot when scrolling through logs.

The culprit is in OpenShockContext.cs, in the AdminUsersView mapping:

entity.Property(e => e.Roles)
    .HasColumnType("role_type[]")
    .HasColumnName("roles")
    .HasConversion(x => x.ToArray(), x => x.ToList());

The HasConversion sets up a value converter but no comparer, so EF nags about it.

What's interesting is that the User entity has the exact same List<RoleType> Roles property mapped to the same role_type[] column, but with no conversion at all — and it doesn't warn. Npgsql already knows how to map List<RoleType> <-> role_type[] natively.

So I think the conversion on the view is just redundant and we can drop it entirely to match how User does it:

entity.Property(e => e.Roles)
    .HasColumnType("role_type[]")
    .HasColumnName("roles");

If for some reason we do need to keep the explicit conversion, then the alternative is to give it a proper ValueComparer for List<RoleType>. But dropping it seems cleaner and more consistent with the User mapping.

Either way it's a read-only keyless view, so change tracking / comparison semantics don't really matter here — it's purely about silencing the warning correctly.

Should be a quick one. Just want to confirm removing the conversion doesn't blow up the view materialization before merging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .NET code

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Issue-Status

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions