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

GroupBy DateTime properties doesn't work #912

Closed
isahrnddev6 opened this issue Feb 9, 2017 · 9 comments · Fixed by #2302
Closed

GroupBy DateTime properties doesn't work #912

isahrnddev6 opened this issue Feb 9, 2017 · 9 comments · Fixed by #2302
Labels

Comments

@isahrnddev6
Copy link

Grouping by DateTime properties does not work. EnableQuery attribute throws System.ArgumentException.

Assemblies affected

Microsoft.AspNet.OData 5.9.1

Reproduce steps

Sent a request that contains a grouping transformation on an entity for a DateTime property:
http://services.odata.org/V4/Northwind/Northwind.svc/Orders?$apply=groupby((OrderDate))

Expected result

The service should return grouped data.

Actual result

System.ArgumentException is thrown.

Additional details

@TehWardy
Copy link

TehWardy commented Apr 4, 2017

"Me too" and I think this may be related to #918

@TehWardy
Copy link

TehWardy commented Apr 7, 2017

playing with it a bit more I managed to get this exception information from a simple "~/API/Type?$groupby((DateTimeField))" query ...

{
  "error": {
    "code": "",
    "message": "An error has occurred.",
    "innererror": {
      "message": "Argument types do not match",
      "type": "System.ArgumentException",
      "stacktrace": "   at System.Linq.Expressions.Expression.Bind(MemberInfo member, Expression expression)\r\n   at System.Web.OData.Query.Expressions.AggregationBinder.CreateGroupByMemberAssignments(Type type, IEnumerable`1 properties)\r\n   at System.Web.OData.Query.Expressions.AggregationBinder.BindGroupBy(IQueryable query)\r\n   at System.Web.OData.Query.ApplyQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)\r\n   at System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at System.Web.OData.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)\r\n   at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n   at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
  }
}

Here's the stack trace "cleaned up" ...

System.ArgumentException: Argument types do not match
	at System.Linq.Expressions.Expression.Bind(MemberInfo member, Expression expression)
	at System.Web.OData.Query.Expressions.AggregationBinder.CreateGroupByMemberAssignments(Type type, IEnumerable`1 properties)
	at System.Web.OData.Query.Expressions.AggregationBinder.BindGroupBy(IQueryable query)
	at System.Web.OData.Query.ApplyQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)
	at System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
	at System.Web.OData.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
	at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)
	at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
	at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

@hbdbim
Copy link

hbdbim commented May 31, 2017

+1

@rcreynolds53
Copy link

I am still experiencing issues when trying to groupby a DateTime, is there a work around for this or has it been resolved?

@TehWardy
Copy link

so it's been a good 18 months ... any movement on this @mtroth-microsoft ?

@sc-starman
Copy link

I'm encountered this problem by so far...
Is there any workaround that you can suggest?

@hbdbim
Copy link

hbdbim commented Dec 28, 2018

I'm encountered this problem by so far...
Is there any workaround that you can suggest?

Yes, make a string property that represents your date and groups by it.

@ElizabethOkerio ElizabethOkerio linked a pull request Oct 7, 2020 that will close this issue
2 tasks
@TehWardy
Copy link

@ElizabethOkerio did you check that this works for DateTimeOffset properties too (just highlighting a somewhat obvious escalation).

@ElizabethOkerio
Copy link
Contributor

@TehWardy yes this works for DateTimeOffset properties too. Have you had issues with DateTimeOffset properties? If so, please share.

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

Successfully merging a pull request may close this issue.

7 participants