Skip to content

Query Exception : Null TypeMapping in Sql Tree #22978

Closed

Description

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)

Activity

  1. smitpatel commented on Oct 12, 2020

    @smitpatel
    Contributor

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

  2. smitpatel commented on Oct 13, 2020

    @smitpatel
    Contributor

    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.

  3. added this to the MQ milestone on Oct 16, 2020
  4. added 2 commits that reference this issue on Nov 13, 2020
    33370c5
    f4628ea
  5. modified the milestones: MQ, 6.0.0 on Nov 25, 2020
  6. modified the milestones: 6.0.0, on Jan 27, 2021
  7. modified the milestones: , 6.0.0 on Nov 8, 2021
  8. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions