Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using MakeGenericMethod in our custom LINQ operators #34559

Open
Tracked by #34446
roji opened this issue Aug 28, 2024 · 0 comments
Open
Tracked by #34446

Stop using MakeGenericMethod in our custom LINQ operators #34559

roji opened this issue Aug 28, 2024 · 0 comments

Comments

@roji
Copy link
Member

roji commented Aug 28, 2024

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
Projects
None yet
Development

No branches or pull requests

1 participant