Skip to content

Npgsql8: Contains() doesn't work with HashSet anymore #3420

Closed as duplicate

Description

@spanevin

SomeDbContext.Something.Where(x => new HashSet() { "a", "b" }.Contains(x.Value)).FirstOrDefault()

This worked perfectly with Npgsql6 and EF6 but with EF8 and Npgsql8 it throws an exception:

System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter`2.Sanitize[T](Object value)
   at Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter`2.<>c__DisplayClass6_0`2.<SanitizeConverter>b__1(Object v)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping.CreateParameter(DbCommand command, String name, Object value, Nullable`1 nullable, ParameterDirection direction)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping.NpgsqlArrayTypeMapping`3.CreateParameter(DbCommand command, String name, Object value, Nullable`1 nullable, ParameterDirection direction)

If I change HashSet to List, it works without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions