title: Calculate max date with oData V4
body: <p>I am trying to get the date that records with various status codes were last created. I am issuing this query:</p>
  
  <pre><code>http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(FTP_ORDERS_ID with max as lastCreated))
  </code></pre>
  
  <p>The following error is returned": </p>
  
  <pre><code>{
  "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.BindSelect(IQueryable grouping)\r\n   at System.Web.OData.Query.ApplyQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor, ODataQueryContext queryContext)\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.&lt;CallOnActionExecutedAsync&gt;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.&lt;ExecuteActionFilterAsyncCore&gt;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.&lt;ExecuteAsync&gt;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.&lt;SendAsync&gt;d__1.MoveNext()"
  }
  }
  }
  </code></pre>
  
  <p>If I change the request to: </p>
  
  <pre><code>http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(FTP_ORDERS_ID with max as lastCreated))
  </code></pre>
  
  <p>then it functions properly, so obviously the issue is with the CREATEDDATE field. CREATEDDATE is defined as TIMESTAMP(6) in Oracle and is defined as DateTime in my EF model.</p>
  
  <p>Is there a secret for making max (and other aggregation functions) work with dates? </p>