Skip to content

Using GetQueryAsync with filter odata query, AutoMapper doesn’t use mapping parameters (e.g., userid) when translating the filter expression #246

Closed

Description

@AmirEmilV

When using GetQueryAsync with filter odata query, AutoMapper doesn’t use mapping parameters (e.g., userid) when translating the filter expression — even though the projection itself (ProjectTo) does.

I added automapper parameters to GetQueryAsync as ProjectionSettings, resulted sql query has this parameters value exist in mapping part but in the query filter part it was default value.

Expected Behavior:
Both filter mapping and projection should respect the same parameter values —
if ProjectTo receives a parameter dictionary,
then MapExpression should also evaluate mapped members using those same parameter values.

Actual Behavior:
ProjectTo correctly substitutes the runtime parameter into the SQL.
But filter part uses the default value of parameter or null if nullable.

AutoMapper.AspNetCore.OData.EFCore version 8.0.0.0

Activity

  1. BlaiseD commented on Nov 7, 2025

    @BlaiseD
    Member

    This library filters before projection - so it makes sense.

    Maybe a repro will make your use case clearer?

  2. AmirEmilV commented on Nov 7, 2025

    @AmirEmilV
    ContributorAuthor

    @BlaiseD yes makes sense but it also means that any filtering that depends on a runtime parameter in the mapper will always fail because the query is already created with the default value of this parameter,

    i will create a repro or a test in a PR if that helps.

    i did a fix and tested it.

  3. BlaiseD commented on Nov 7, 2025

    @BlaiseD
    Member

    Go for it. Consider adding an opt-in flag if you plan to filter against the projection.

  4. AmirEmilV commented on Nov 16, 2025

    @AmirEmilV
    ContributorAuthor

    Created a PR

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

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