efcore
efcore copied to clipboard
Can't translate comparison operators on unsigned long to SQL when using SQLite
Edit: This is probably because SQLite doesn't support UInt64 internally.
Sorry if this is a duplicate, the only directly relevant issue I found was #12045.
Equality operators work, but comparison operators don't. Signed longs also work correctly.
Exception message: Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'where ([n].unsignedLong < 0)' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
Stack trace: StackTrace " at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`1.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, WarningBehavior warningBehavior, TParam arg, Exception exception)\r\n at Microsoft.EntityFrameworkCore.Internal.RelationalLoggerExtensions.QueryClientEvaluationWarning(IDiagnosticsLogger`1 diagnostics, QueryModel queryModel, Object queryModelElement)\r\n at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)\r\n at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)\r\n at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)\r\n at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)\r\n at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)\r\n at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)\r\n at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0`1.<Execute>b__0()\r\n at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)\r\n at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)\r\n at Remotion.Linq.QueryableBase`1.GetEnumerator()\r\n at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Program.Main(String[] args) in [Snip]\\ClientFilteringTest\\Program.cs:line 15" string
Steps to reproduce
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
class Program
{
static void Main(string[] args)
{
using (DatabaseCtx context = new DatabaseCtx())
{
Console.WriteLine(context.Numbers.Where(n => n.signedLong < 0).ToList());
try { List<Number> numbers = context.Numbers.Where(n => n.unsignedLong < 0).ToList(); }
catch (InvalidOperationException e) { Console.WriteLine(e.Message); }
}
Console.ReadKey();
}
}
public class Number
{
[Key]
public ulong unsignedLong { get; set; }
public long signedLong { get; set; }
}
public class DatabaseCtx : DbContext
{
public DbSet<Number> Numbers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=numbers.sqlite").ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));
}
}
Further technical details
EF Core version: 2.2.4 Database Provider: Microsoft.EntityFrameworkCore.Sqlite Operating system: Windows 10 1803 IDE: Visual Studio 2017 15.9.8