The LINQ expression 'Is Nothing' could not be translated VB.NET
See original GitHub issueProblem with LINQ Query, fails when expression contains “Is Nothing” / “IsNot Nothing”. The problem occurs only in project language VB.NET.
Steps to reproduce
VB.NET
Dim q = (from t in DC.Customer WHERE t.telephone Is Nothing)
Exception:
InvalidOperationException: Null TypeMapping in Sql Tree
en Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
en System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlBinaryExpression.VisitChildren(ExpressionVisitor visitor)
en Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
en System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlBinaryExpression.VisitChildren(ExpressionVisitor visitor)
en Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
en System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlBinaryExpression.VisitChildren(ExpressionVisitor visitor)
en Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
en System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlBinaryExpression.VisitChildren(ExpressionVisitor visitor)
en Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
en System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
en Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
en Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
en Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
en System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
en Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
en System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
en System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
en Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
en Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
en Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
en Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
en Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
en Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
en Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
en Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
en Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
en System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
en Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__64`1.MoveNext()
en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
en System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
The same query in C# project works perfectly. The traslation:
SELECT * FROM customer where telephone IS NULL
Further technical details
EF Core version: 3.1 Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: .NET 4.6.1 Operating system: Windows 10 Pro IDE: Visual Studio 2019 16.4
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
c# - The LINQ expression could not be translated and will ...
I got this error by querying my LINQ methods in the wrong order before calling a ToListAsync call at the end. Here was...
Read more >LINQ Expression Could not Be Translated - Microsoft Q&A
Hello everyone and thanks for the help in advance. I am creating a MVC application uisng .Net 6 and EF 6 to query...
Read more >Invalidoperationexception: the LINQ expression
You are misusing the property and EF cannot translate that. In order to use an expression in LINQ it must be translatable to...
Read more >Invalidoperationexception: the LINQ expression for groupby
FirstOrDefault()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly ...
Read more >Microsoft SQL Server 2008 R2 Unleashed - Google Books Result
When you use this C# syntax convention, you don't have to set up a finally block that ... NET objects, it's time to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ajcvickers Found a suitable solution for me. The EF Core Project is C# so I combined this commit (https://github.com/dotnet/efcore/pull/21125) with https://github.com/dotnet/efcore/issues/19592#issuecomment-577823867
Base files are from https://github.com/dotnet/efcore/issues/19592#issuecomment-577823867
LanguageNormalizingExpressionVisitor.cs
SharedTypeExtensions.cs
VisualBasicRelationalQueryTranslationPreprocessor.cs
VisualBasicRelationalQueryTranslationPreprocessorFactory .cs
@ChristophWeigert You’ll probably need to re-write the LINQ expression tree. @smitpatel @roji Would a method translator work here?