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

EF.CompileQuery parameters #20606

Closed
shivakumarb1989 opened this issue Apr 12, 2020 · 13 comments
Closed

EF.CompileQuery parameters #20606

shivakumarb1989 opened this issue Apr 12, 2020 · 13 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@shivakumarb1989
Copy link

shivakumarb1989 commented Apr 12, 2020

Currrently EF.CompileQuery supports 5 parameters for querying.

Having said this the EF does not support client evaluation, passing a class as a parameter to EF.CompileQuery throws (limitation / client evaluation) a bug.
I would like to understand if i can achieve atleast 12 parameters(by overloading/extending) the EF.CompileQuery for querying.
Is there any way that we can support more parameters. Or are their any work arounds to acheive this feature.

In future releases are you guys planning to support more parameters? Please let me know your thoughts.

Thanks a lot.

@ajcvickers
Copy link
Member

@smitpatel Why do we only have API for up to five parameters?

@ajcvickers
Copy link
Member

Notes from team discussion:

  • Add more TParam overloads--up to at least 15
  • Add params object array support for more parameters

@ajcvickers ajcvickers added this to the 5.0.0 milestone Apr 13, 2020
@shivakumarb1989
Copy link
Author

Hi @ajcvickers @smitpatel , Could you please provide any documentation of EF.CompileQuery examples if any? Many Thanks.

@smitpatel
Copy link
Member

smitpatel commented Apr 14, 2020

Add params object array support for more parameters

@dotnet/efcore - Can someone explain? An example of API?

smitpatel added a commit that referenced this issue Apr 14, 2020
Part of #20606

Upto 15 parameters are allowed. We cannot go further than that. Our return type is Func<> which does not allow more than 16 in parameters. One fixed parameter is TContext.
Due to same limitation, the CompileAsyncQuery which also takes cancellationToken can support only upto 14 other parameters.
@AndriySvyryd
Copy link
Member

@dotnet/efcore - Can someone explain? An example of API?

        public static Func<TContext, <#= paramsList #>object[], IEnumerable<TResult>> CompileQuery<TContext, <#= paramsList #>TResult, TProperty>(
[NotNull] Expression<Func<TContext, <#= paramsList #>object[], IIncludableQueryable<TResult, TProperty>>> queryExpression)
            where TContext : DbContext

@smitpatel
Copy link
Member

Without true funcletizer it does not work in current implementation.
Using 3.1 packages, below fail because we cannot translate ArrayAccess over a parameter.

                var query = EF.CompileQuery((MyContext context, object[] parameters)
                    => context.Blogs.Where(b => b.Id == (int)parameters[0]));

                query(db, new object[] { 1 }).ToList();

smitpatel added a commit that referenced this issue Apr 14, 2020
Part of #20606

Upto 15 parameters are allowed. We cannot go further than that. Our return type is Func<> which does not allow more than 16 in parameters. One fixed parameter is TContext.
Due to same limitation, the CompileAsyncQuery which also takes cancellationToken can support only upto 14 other parameters.
@shivakumarb1989
Copy link
Author

Woah! I can see there is a pull request for 15 parameters. When can we expect this to be published @smitpatel , thanks. :)

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 14, 2020
smitpatel added a commit that referenced this issue Apr 14, 2020
Resolves #20606

Upto 15 parameters are allowed. We cannot go further than that. Our return type is Func<> which does not allow more than 16 in parameters. One fixed parameter is TContext.
Due to same limitation, the CompileAsyncQuery which also takes cancellationToken can support only upto 14 other parameters.
@shivakumarb1989
Copy link
Author

Hi @ajcvickers , @smitpatel . is this feature going to be released in any of the EF core 3.1.x versions? This is something we are looking for in our project. Many thanks.

@AndriySvyryd
Copy link
Member

@shivakumarb1989 3.1.x only contain critical bug fixes. All implemented featured will be released in 5.0.0

@shivakumarb1989
Copy link
Author

Ok cool. Thanks for the update @AndriySvyryd

@shivakumarb1989
Copy link
Author

Hi All, One last question. Could we combine multiple EF.CompileQueries? to achieve more parameters. Or is there a work around for this in 3.1.x? many thanks.

@smitpatel
Copy link
Member

Work-around would involve adding additional method in the own code.
Add a static method in your own code like one of this. Difference between all 3 method is ending. If your lambda ends with result of type IQueryable or scalar/single result or ends with include. You only need to add the method you are using.
https://github.com/dotnet/efcore/blob/release/3.1/src/EFCore/EF.CompileQuery.cs#L268-L321

The implementation of method uses https://github.com/dotnet/efcore/blob/release/3.1/src/EFCore/Query/Internal/CompiledQuery.cs class, just derive from it, add Execute method with number of parameters you need and use that in implementation. CompiledQuery.cs is in Internal namespace so it can break between releases. But it should work for release/3.1. From 5.0 you wouldn't need a work-around.

@shivakumarb1989
Copy link
Author

Great. Many thanks @smitpatel . Will try that.

@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview4 Apr 20, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview4, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

No branches or pull requests

5 participants