[EF Core] NullReferenceException when using Where

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
dejvid
Posts: 1
Joined: Wed 05 Dec 2018 14:34

[EF Core] NullReferenceException when using Where

Post by dejvid » Thu 27 Jun 2019 13:27

Hi,

I'm having issue when using Where LINQ method with nullable bool with configured value conversion to string.

Example:

Code: Select all

public class Item {
    public bool? Active { get; set; }
}

class MyContext : DbContext {
	protected override void OnModelCreating(ModelBuilder modelBuilder) {
            modelBuilder.Query<Item>()
                .Property(p => p.Active)
                .HasColumnName("ACTIVE")
                .HasConversion(new BoolToStringConverter("N", "Y"));
        }
}

using(var context = new MyContext ()) {
    context.Set<Item>()
                .Where(x => x.Active == true)
                .ToList();
}
The above ToList() call throws NullReferenceException while generating the SQL.

Note that when I change the condition to

Code: Select all

x.Active == false
it works but I need it to work in both cases.

Package version: Devart.Data.Oracle.EFCore 9.7.770

I have also tried several older versions of the package but they don't work.

I guess the exception details won't tell you much but here it is anyway

Code: Select all

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Devart.Data.Oracle.Entity.EFCore
  StackTrace:
   at   .(String )
   at   .      (Object , Int32 )
   at   .(Object ,    , Int32 )
   at   .     (  )
   at   .(String , Expression , Expression )
   at   .(BinaryExpression )
   at   .VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at   .GeneratePredicate(Expression )
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.VisitSelect(SelectExpression selectExpression)
   at   .VisitSelect(SelectExpression )
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.GenerateSql(IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalExpressionPrinter.CommandBuilderPrinter.TryPrintConstant(ConstantExpression constantExpression, IndentedStringBuilder stringBuilder, Boolean removeFormatting)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitConstant(ConstantExpression constantExpression)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitLambda[T](Expression`1 lambdaExpression)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.PrintInternal(Expression expression, Boolean removeFormatting, Nullable`1 characterLimit, Boolean highlightNonreducibleNodes, Boolean reduceBeforePrinting, Boolean generateUniqueQsreIds, Boolean printConnections)
   at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Print(Expression expression, Boolean removeFormatting, Nullable`1 characterLimit, Boolean printConnections)
   at Microsoft.EntityFrameworkCore.Internal.CoreLoggerExtensions.QueryExecutionPlanned(IDiagnosticsLogger`1 diagnostics, IExpressionPrinter expressionPrinter, Expression queryExecutorExpression)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateExecutorLambda[TResults]()
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Remotion.Linq.QueryableBase`1.GetEnumerator()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ConsoleApp1.Program.Main(String[] args) in C:\temp\ConsoleApp1\ConsoleApp1\Program.cs:line 20

Shalex
Site Admin
Posts: 8988
Joined: Thu 14 Aug 2008 12:44

Re: [EF Core] NullReferenceException when using Where

Post by Shalex » Wed 03 Jul 2019 19:03

Thank you for your report. We have reproduced the issue and are investigating it.

Shalex
Site Admin
Posts: 8988
Joined: Thu 14 Aug 2008 12:44

Re: [EF Core] NullReferenceException when using Where

Post by Shalex » Wed 24 Jul 2019 14:22

The bug with applying a value converter to a nullable column in EF Core 2 is fixed. We will notify you when the new build is available.

With the fixed version, you should add .HasColumnType("VARCHAR2") to the mapping of the Active property.

Shalex
Site Admin
Posts: 8988
Joined: Thu 14 Aug 2008 12:44

Re: [EF Core] NullReferenceException when using Where

Post by Shalex » Fri 26 Jul 2019 09:46

New build of dotConnect for Oracle 9.7.805 is available for download: viewtopic.php?f=1&t=39081.

Post Reply