【发布时间】:2019-01-25 20:01:33
【问题描述】:
Entity Framework Core (SQL Sever) 和 Asp.Net Core 上的简单 OData 聚合失败:
odata/file?$apply=groupby((FileType))
由于无法翻译使用的 GroupBy LINQ 表达式,发出警告:
Microsoft.EntityFrameworkCore.Query: Warning: The LINQ expression 'GroupBy(new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = "FileType", Value = [$it].FileType}}, [$it])' could not be translated and will be evaluated locally.
然后抛出异常:
system.security.verificationexception operation could destabilize the runtime
最相关的堆栈:
at lambda_method(Closure , File )
at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.GroupedEnumerable`3.GetEnumerator()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
使用的 NuGet 包版本:
- Microsoft.AspNetCore.OData 7.0.1
- Microsoft.EntityFrameworkCore.SqlServer 2.1.1
- Microsoft.AspNetCore 2.1.2
显示问题的回购:https://github.com/xmichaelx/ODataGroupByTest
GitHub 上的问题:https://github.com/OData/WebApi/issues/1578
我不确定问题出在哪里,EF Core 是否应该能够将 LINQ 查询转换为有效的 SQL 或 OData 生成难以转换的 GroupBy 表达式。在解决之前,我正在寻找一些解决方法。
【问题讨论】:
标签: c# asp.net-core odata entity-framework-core linq2db