Skip to content

Stop using MakeGenericMethod in our custom LINQ operators #34559

Open

Description

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)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions