Skip to content

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

Closed as not planned

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

Activity

  1. MihuBot commented on Sep 26, 2025

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  2. AndriySvyryd commented on Sep 26, 2025

    @AndriySvyryd
    Member

    @Inspirateur Could you provide a small repro console app project? The above snippets are not enough to reproduce the issue.

  3. Inspirateur commented on Sep 27, 2025

    @Inspirateur
    Author

    @Inspirateur Could you provide a small repro console app project? The above snippets are not enough to reproduce the issue.

    I can't send the original code (proprietary) but i'll do my best to create a minimal project on monday :)

    I'm surprised the snippets weren't enough though! I really thought it included all the elements that mattered.

    I think the main issue for EF 9 is that I'm doing EF.Property<int>(cf!, PropertyName) on a property which is technically not an int (even though it's stored as an int in the DB).

    A workaround that works for me is adding another generic type which represents the exact type of the property I'm querying, and then converting it to a int like so: Convert.ToInt32(EF.Property<TKey>(cf!, PropertyName))

  4. cincuranet commented on Oct 3, 2025

    @cincuranet
    Contributor

    EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

    BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions