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

Query Exception : Null TypeMapping in Sql Tree #22978

Closed
ghost opened this issue Oct 12, 2020 · 7 comments · Fixed by #23321
Closed

Query Exception : Null TypeMapping in Sql Tree #22978

ghost opened this issue Oct 12, 2020 · 7 comments · Fixed by #23321
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@ghost
Copy link

ghost commented Oct 12, 2020

This query:

{value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[RIAppDemo.DAL.EF.Product]).AsNoTracking().Where(Param_0 => (Convert(Param_0.Size, Object) == null)).OrderBy(Param_1 => Param_1.Name).ThenByDescending(Param_1 => Param_1.SellStartDate).Skip(0).Take(50)}

produces "Null TypeMapping in Sql Tree" exception inside Microsoft.EntityFrameworkCore.Relational

  at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlBinaryExpression.VisitChildren(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.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__DisplayClass12_0`1.<ExecuteAsync>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.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at RIAppDemo.BLL.DataServices.DataManagers.ProductDM.<>c.<ReadProduct>b__0_0(IQueryable`1 countQuery) in c:\DATA\DEVELOP\JRIAppCore31\DEMOS\RIAppDemoMVC\RIAppDemo.BLL\DataManagers\ProductDM .cs:line 21
   at RIAPP.DataService.Core.Query.QueryEx.<>c__DisplayClass8_0`1.<PerformQuery>b__1() in c:\DATA\DEVELOP\JRIAppCore31\FRAMEWORK\SERVER\RIAPP.DataService\Extensions\Query\QueryEx.cs:line 211
   at RIAppDemo.BLL.DataServices.DataManagers.ProductDM.<ReadProduct>d__0.MoveNext() in c:\DATA\DEVELOP\JRIAppCore31\DEMOS\RIAppDemoMVC\RIAppDemo.BLL\DataManagers\ProductDM .cs:line 22
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RIAPP.DataService.Core.ServiceOperationsHelper`1.<GetMethodResult>d__32.MoveNext() in c:\DATA\DEVELOP\JRIAppCore31\FRAMEWORK\SERVER\RIAPP.DataService\Core\ServiceOperationsHelper.cs:line 533
   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 RIAPP.DataService.Core.UseCases.QueryMiddleware.ExecuteMiddleware`1.<Invoke>d__2.MoveNext() in c:\DATA\DEVELOP\JRIAppCore31\FRAMEWORK\SERVER\RIAPP.DataService\Core\UseCases\QueryMiddleware\ExecuteMiddleware.cs:line 44
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RIAPP.DataService.Core.UseCases.QueryMiddleware.AuthorizeMiddleware`1.<Invoke>d__2.MoveNext() in c:\DATA\DEVELOP\JRIAppCore31\FRAMEWORK\SERVER\RIAPP.DataService\Core\UseCases\QueryMiddleware\AuthorizeMiddleware.cs:line 25
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RIAPP.DataService.Core.QueryOperationsUseCase`1.<Handle>d__5.MoveNext() in c:\DATA\DEVELOP\JRIAppCore31\FRAMEWORK\SERVER\RIAPP.DataService\Core\UseCases\QueryOperationsUseCase.cs:line 54

The filter condition in the query is created using Dynamic Linq library, but exception is occured only when using equals (or not equals) to null value
This can be reproduced using this DEMO project: Demo Project
The github repo: https://github.com/BBGONE/JRIApp.Core

This project has several demo pages, the bug is exposed in the DataGrid Demo, when i try to filter results by selecting for product table, filter
Screenshot_2020-10-12 DataGrid Demo
condition for Size : EMPTY or NOT EMPTY.

Include provider and version information

EF Core version: 3.1.8
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Operating system: Windows 10 Professional
IDE: (e.g. Visual Studio 2019 16.7.5)

@ghost ghost added the customer-reported label Oct 12, 2020
@ghost
Copy link
Author

ghost commented Oct 12, 2020

By the way, i tried the same query in Entity Framework Core 2.0 and it works as expected (no exception)
The same repo contains branch which uses EF.Core 2.0 in the same demo project https://github.com/BBGONE/JRIApp.Core/tree/net-core-3.1-using-EF2.0

So it is only produces error in EF.Core 3.1 (in my case 3.1.8)

@smitpatel
Copy link
Member

Can you try with 5.0 nightly packages? We believe that this issue is fixed in 5.0

@ghost
Copy link
Author

ghost commented Oct 13, 2020

Yes, in version 5.0.0-rc.1.20451.13 it works as expected.
Is the current 3.1 version is no longer supported?

@smitpatel
Copy link
Member

3.1 is current LTS version and is supported. But like with every other product, we fix bugs in current release as product moves forward. We patch bugs in older release according to our patch policy. You can read more about our patch policy here - https://docs.microsoft.com/en-us/ef/core/what-is-new/release-planning#patch-releases

This particular issue is fixed in 5.0 release. In order to backport it to 3.1 release, it requires to match patch release criteria.
In this case, bug is because of additional convert to object introduced in the tree when comparing to null. Since the type of the column is string, it can be compared to null directly without any convert node since string is reference type. If you write LINQ query directly, that is the expression tree compiler would generate. Hence the external library is generating unusual tree which makes it a corner-case bug. We will discuss in next team meeting. But this may not get backported to 3.1 release.

@ghost
Copy link
Author

ghost commented Oct 13, 2020

OK, but take in consideration, that this query works in EF 6 for Net Framework, EF.Core 2.0, and for consistency it is good to be working in EF 3.1. It seems a breaking change without a good reason - because the expression is perfectly valid (the Convert function is supported) and must be translated to SQL without problems.

@ghost
Copy link
Author

ghost commented Oct 14, 2020

I updated the Dynamic Linq library (my version of it), so it would not use the Convert function in this case, so my code is working as expected, now

@AndriySvyryd AndriySvyryd added type-bug verify-fixed This issue is likely fixed in new query pipeline. labels Oct 16, 2020
@AndriySvyryd AndriySvyryd added this to the MQ milestone Oct 16, 2020
@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. labels Nov 13, 2020
maumar added a commit that referenced this issue Nov 13, 2020
@maumar maumar closed this as completed in f4628ea Nov 14, 2020
@ajcvickers ajcvickers modified the milestones: MQ, 6.0.0 Nov 25, 2020
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview1 Jan 27, 2021
@ghost
Copy link

ghost commented May 26, 2021

I ran into this bug this morning. I read smitpatel's post from Oct 2020 with a mixture of anger, frustration and 'It figures'. I am using an officially supported version with a status of LTS and the response seems to be 'meh'. This is why developers have such a low opinion of MS. You leave us hanging. My situation is a double whammy since I am working on a UWP app which was promoted by MS as the go to cross platform framework up until the point that it wasn't and now seems to be the unwanted step child. Because MS has not kept up with UWP, the 5.0 versions are not compatible and developers are stuck with 3.1, which really isn't stuck considering that it is LTS, but wait, that really doesn't mean much if the bug doesn't meet certain criteria.

Since several months have past, is there any update to the status of fixing this bug in the 3.1.x versions?

@ajcvickers ajcvickers modified the milestones: 6.0.0-preview1, 6.0.0 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants