Skip to content

Stop using MakeGenericMethod in our custom LINQ operators #34559

Description

@roji

Our custom LINQ operator are currently implemented as follows, more or less:

return
    source.Provider is EntityQueryProvider
        ? source.Provider.CreateQuery<TEntity>(
            Expression.Call(
                instance: null,
                method: WithPartitionKeyMethodInfo1.MakeGenericMethod(typeof(TEntity)),
                source.Expression,
                Expression.Constant(partitionKeyValue, typeof(object))))
        : source;

This is a needless use of MakeGenericMethod, which is both less efficient and problematic for NativeAOT. Instead, we can use the following pattern in use in the standard LINQ operators (see dotnet/runtime#79717):

return source.Provider.CreateQuery<TSource>(
    Expression.Call(
        null,
        new Func<IQueryable<TSource>, int, IQueryable<TSource>>(Skip).Method,
        source.Expression, Expression.Constant(count)));

Activity

  1. added this to the Backlog milestone on Aug 28, 2024
  2. added theissue type on Jun 15, 2025
  3. modified the milestones: Backlog, 11.0.0 on Dec 13, 2025
  4. self-assigned this
    on Dec 13, 2025
  5. added a commit that references this issue on Dec 13, 2025
    7f95bf4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions