dataobjects-net
dataobjects-net copied to clipboard
Odata groupby not working
Running the following odata query, the DataObjects throws an error:
Sample: https://github.com/fairking/DoOdataTest
Query: https://localhost:5001/odata/weatherforecast?$apply=groupby((summary), aggregate(temperatureC with average as total))
Error:
Xtensive.Orm.QueryTranslationException: Unable to translate 'Query.All().Select(dtoWeatherForecast => new WeatherForecastVm() {
Date = dtoWeatherForecast.Date,
Id = dtoWeatherForecast.Id,
Summary = dtoWeatherForecast.Summary,
TemperatureC = dtoWeatherForecast.TemperatureC,
TemperatureF = (32 + ((Int32)(((Double)dtoWeatherForecast.TemperatureC) / 0.5556)))
}).Select($it => new FlatteningWrapper<WeatherForecastVm>() {
Source = $it,
GroupByContainer = new AggregationPropertyContainer.LastInChain() {
Name = "Property0",
Value = ((Object)$it.TemperatureC)
}
}).GroupBy($it => new GroupByWrapper() {
GroupByContainer = new AggregationPropertyContainer.LastInChain() {
Name = "summary",
Value = $it.Source.Summary
}
}).Select($it => new AggregationWrapper() {
GroupByContainer = $it.Key.GroupByContainer,
Container = new AggregationPropertyContainer.LastInChain() {
Name = "total",
Value = ((Object)((IEnumerable<FlatteningWrapper<WeatherForecastVm>>)$it).Average($it => ((Int32)$it.GroupByContainer.Value)))
}
})' expression. See inner exception for details.
---> System.NotSupportedException: Specified method is not supported.
at Xtensive.Orm.Providers.ExpressionProcessor.VisitMemberInit(MemberInitExpression mi)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e, Boolean smartNull)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.VisitMemberAccess(MemberExpression m)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e, Boolean smartNull)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.VisitUnary(UnaryExpression expression)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e, Boolean smartNull)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.VisitUnary(UnaryExpression expression)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e, Boolean smartNull)
at Xtensive.Orm.Providers.ExpressionProcessor.VisitLambda(LambdaExpression l)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e, Boolean smartNull)
at Xtensive.Orm.Providers.ExpressionProcessor.Visit(Expression e)
at Xtensive.Orm.Providers.ExpressionProcessor.Translate()
at Xtensive.Orm.Providers.SqlCompiler.ProcessExpression(LambdaExpression le, List`1[] sourceColumns)
at Xtensive.Orm.Providers.SqlCompiler.VisitCalculate(CalculateProvider provider)
at Xtensive.Orm.Rse.Compilation.Compiler`1.Compile(CompilableProvider cp)
at Xtensive.Orm.Providers.SqlCompiler.VisitAggregate(AggregateProvider provider)
at Xtensive.Orm.Rse.Compilation.Compiler`1.Compile(CompilableProvider cp)
at Xtensive.Orm.Providers.SqlCompiler.VisitApply(ApplyProvider provider)
at Xtensive.Orm.Rse.Compilation.Compiler`1.Compile(CompilableProvider cp)
at Xtensive.Orm.Rse.Compilation.Compiler`1.Xtensive.Orm.Rse.Compilation.ICompiler.Compile(CompilableProvider provider)
at Xtensive.Orm.Providers.CompilationService.Compile(CompilableProvider provider, CompilerConfiguration configuration)
at Xtensive.Orm.Linq.Translator.Translate[TResult](ProjectionExpression projection, IEnumerable`1 tupleParameterBindings)
at Xtensive.Orm.Linq.Translator.Translate[TResult]()
at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression, CompilerConfiguration compilerConfiguration)
--- End of inner exception stack trace ---
at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression, CompilerConfiguration compilerConfiguration)
at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression)
at Xtensive.Orm.Linq.QueryProvider.Execute[TResult](Expression expression)
at Xtensive.Orm.Linq.Queryable`1.GetEnumerator()
at Xtensive.Orm.Linq.Queryable`1.System.Collections.IEnumerable.GetEnumerator()
at System.Text.Json.JsonSerializer.HandleEnumerable(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Hello,
This will fail since it uses custom types DataObjects.Net even doesn't know about. DataObjects.Net ExperssionVisitor takes care of Expression structure it familiar with.
Unfortunately, there is no support for these types in DataObjects.Net yet