Skip to content

Better error when trying to use EF.Constant/Parameter with compiled queries and query filters #38151

Closed

Description

@roji

We currently throw a cryptic:

System.InvalidCastException: Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'Microsoft.EntityFrameworkCore.Query.QueryParameterExpression'.

See #33674 for the original change in the EF.Constant/Parameter implementation that introduced the incompatibility with compiled queries; and #38150 for a recent report triggering this issue.

Activity

  1. added this to the 11.0.0 milestone on Apr 21, 2026
  2. self-assigned this
    on Apr 21, 2026
  3. added theissue type on Apr 21, 2026
  4. MihuBot commented on Apr 21, 2026

    @MihuBot

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

  5. added a commit that references this issue on Apr 22, 2026
    22ba473
  6. changed the title [-]Better error when trying to use EF.Constant/Parameter with compiled queries[/-] [+]Better error when trying to use EF.Constant/Parameter with compiled queries and query filters[/+] on Apr 22, 2026
  7. added a commit that references this issue on Apr 22, 2026
    4bd878e
  8. added a commit that references this issue on Apr 23, 2026
    e87c07b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions