'EF Core ValueComparer HashSet of Enums

I'm using code first and have this entity:

public class TaskFeedReactionsModel
{
    public string UserId { get; set; }
    public ApplicationUser User { get; set; }
    public int TaskFeedId { get; set; }
    public TaskFeedModel TaskFeed { get; set; }        
    public HashSet<CommentEnums.CommentReactions> Reactions { get; set; }
}

My modelBuilder in the AppDBContext will have to covert the "Reactions" property:

taskFeedReactions.Property(p => p.Reactions)
            .HasConversion(x => string.Join(',', x),
            x => new HashSet<CommentEnums.CommentReactions>(
                x.Split(',', StringSplitOptions.RemoveEmptyEntries)
                .Select(y => (CommentEnums.CommentReactions)Enum
                .Parse(typeof(CommentEnums.CommentReactions), y))));  

The problem now is that I want to add a comparer to it but cant manage how to do it. I tryied like this:

taskFeedReactions.Property(p => p.Reactions)
            .HasConversion(x => string.Join(',', x),
            x => new HashSet<CommentEnums.CommentReactions>(
                x.Split(',', StringSplitOptions.RemoveEmptyEntries)
                .Select(y => (CommentEnums.CommentReactions)Enum
                .Parse(typeof(CommentEnums.CommentReactions), y)),
                new ValueComparer<HashSet<CommentEnums.CommentReactions>>(
                (c1, c2) => c1.SequenceEqual(c2),
                c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
                c => c.ToHashSet())));    

But the following error is being shown:

Argument 2: cannot convert from 'Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer<System.Collections.Generic.HashSet<Data.Enums.CommentEnums.CommentReactions>>' to 'System.Collections.Generic.IEqualityComparer<Data.Enums.CommentEnums.CommentReactions>?'

Does anyone know hwo to do this?

Bests



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source