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

$count is evaluated prematurely at the call queryOptions.ApplyTo #1

Closed
congysu opened this issue Jan 5, 2015 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@congysu
Copy link
Contributor

congysu commented Jan 5, 2015

internal static class ExpressionHelpers
{
    public static long Count(IQueryable query, Type type)
    {
        MethodInfo countMethod = ExpressionHelperMethods.QueryableCountGeneric.MakeGenericMethod(type);
        return (long)countMethod.Invoke(null, new object[] { query });
    }

A query
http://localhost:31181/api/northwind/Products?$count=true
will evaluate the query expression prematurely at the call
queryable = queryOptions.ApplyTo(queryable, settings);

This breaks RESTier, specifically, in DomainControllers.GetQuery method.
Since at that time QuerySourcer has not intervened in, the placeholder class QueryableSource will be queried against, and exception will be thrown.

Call stack:

System.Web.OData.dll!System.Web.OData.ExpressionHelpers.Count(System.Linq.IQueryable query, System.Type type) Line 18 C#
System.Web.OData.dll!System.Web.OData.Query.CountQueryOption.GetEntityCount(System.Linq.IQueryable query) Line 138 C#
System.Web.OData.dll!System.Web.OData.Query.ODataQueryOptions.ApplyTo(System.Linq.IQueryable query, System.Web.OData.Query.ODataQuerySettings querySettings) Line 239 C#

@congysu
Copy link
Contributor Author

congysu commented Mar 25, 2015

Checked in 5332139.

@LianwMS LianwMS closed this as completed Mar 26, 2015
@congysu congysu modified the milestones: v5.8, V5.5 Aug 9, 2015
@congysu congysu reopened this Aug 9, 2015
@congysu congysu assigned VikingsFan and unassigned LianwMS Nov 13, 2015
@lewischeng-ms
Copy link
Contributor

RESTier can call ODataQueryOptions.ApplyTo with ignoreQueryOptions set to AllowedQueryOptions.Count to work around this issue. And then later set the TotalCount to QueryResult in QueryExecutor.

@VikingsFan VikingsFan reopened this Nov 16, 2015
VikingsFan added a commit to VikingsFan/WebApi that referenced this issue Nov 16, 2015
VikingsFan added a commit to VikingsFan/WebApi that referenced this issue Nov 17, 2015
VikingsFan added a commit to VikingsFan/WebApi that referenced this issue Nov 18, 2015
@VikingsFan
Copy link
Contributor

Merged 337a8cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants