Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[9 regression] No coercion operator is defined between types #36873

@Inspirateur

Description

@Inspirateur

Bug description

Context: we have multi-select drop-downs that we use to filter data server-side in a Grid.

The setup is somewhat convoluted and ends up calling this function:

public IQueryable<T> Filter<T>(IQueryable<T> source) {
    return source.Where(cf => SelectedKeys.Contains(EF.Property<int>(cf!, PropertyName)));
}

With:

  • SelectedKeys : HashSet<int>
  • T something like:
[Table("MailHistory")]
public class MailHistoryEntity 
{
    ...
    public MailHistoryStatus MailHistoryStatus { get; set; }
}
  • PropertyName = "MailHistoryStatus"
  • MailHistoryStatus an enum

This worked without issues in EF Core 8, but in EF Core 9 it crashes with:

Error: System.Reflection.TargetInvocationException: 
Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: No coercion operator is defined between types
'Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1[PROJECT_NAME.Enums.MailHistoryStatus]' and 
'Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1[System.Int32]'.

EF Core version

9

Database provider

SQL Server

Target framework

.net 8

Operating system

Windows 11

IDE

Visual Studio 2022

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions