Skip to content

Stop using MakeGenericMethod in our custom LINQ operators #34559

@roji

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)));

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions