DevExpress / DevExtreme.AspNet.Data

DevExtreme data layer extension for ASP.NET
MIT License
152 stars 128 forks source link

Unable to cast object of type 'Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlUnaryExpression' to type 'System.Linq.Expressions.ConstantExpression'. #428

Closed mm-ryo closed 4 years ago

mm-ryo commented 4 years ago

I just try click data-grid column filter. I have got this error.

"devextreme": "^19.2.6",
"devextreme-angular": "^19.2.6",
"devextreme-aspnet-data-nojquery": "^2.5.1",

VS2019 16.5.5 EF Core 3.1.3 .NET Core 3.1

at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.GetProjectionIndex(ProjectionBindingExpression projectionBindingExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.VisitExtension(Expression extensionExpression)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)
   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.Visit(Expression node, IReadOnlyList`1& projectionColumns)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.VisitShapedQueryExpression(ShapedQueryExpression shapedQueryExpression)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at DevExtreme.AspNet.Data.GroupHelper`1.Group(IEnumerable`1 data, GroupingInfo groupInfo) in E:\Projects\DevExtreme.AspNet.Data\net\DevExtreme.AspNet.Data\GroupHelper.cs:line 41
   at DevExtreme.AspNet.Data.GroupHelper`1.Group(IEnumerable`1 data, IEnumerable`1 groupInfo) in E:\Projects\DevExtreme.AspNet.Data\net\DevExtreme.AspNet.Data\GroupHelper.cs:line 22
   at DevExtreme.AspNet.Data.RemoteGrouping.RemoteGroupTransformer.Run(Type sourceItemType, IEnumerable`1 flatGroups, Int32 groupCount, IReadOnlyList`1 totalSummary, IReadOnlyList`1 groupSummary) in E:\Projects\DevExtreme.AspNet.Data\net\DevExtreme.AspNet.Data\RemoteGrouping\RemoteGroupTransformer.cs:line 18
   at DevExtreme.AspNet.Data.DataSourceLoaderImpl`1.<ExecRemoteGroupingAsync>d__14.MoveNext() in E:\Projects\DevExtreme.AspNet.Data\net\DevExtreme.AspNet.Data\DataSourceLoaderImpl.cs:line 181
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at DevExtreme.AspNet.Data.DataSourceLoaderImpl`1.<LoadAsync>d__7.MoveNext() in E:\Projects\DevExtreme.AspNet.Data\net\DevExtreme.AspNet.Data\DataSourceLoaderImpl.cs:line 51
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at DevExtreme.AspNet.Data.DataSourceLoader.Load[T](IQueryable`1 source, DataSourceLoadOptionsBase options) in E:\Projects\DevExtreme.AspNet.Data\net\DevExtreme.AspNet.Data\DataSourceLoader.cs:line 35
mm-ryo commented 4 years ago

It's due to IQueryable result with customize function called. In ef core 3.0 there is a breaking change and I need to call AsEnumerable() .

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#linq-queries-are-no-longer-evaluated-on-the-client

fthdtc commented 1 year ago

Hi, in .net core 3.1, I found a solution for this issue to concat string instead of string formatting as result. I got this error when distinct my queryable on results and switch $"name:{name}-surname:{surname}" to "name:"+name+"surname:"+surname; and error is gone.