efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Cannot parse boolean field condition without "== true" in a chainend expression

Open gisek opened this issue 10 years ago • 6 comments

Steps to reproduce

Everything is fine, if the expression has no joins. When there is a join, I have to explicitly add == true at the end of the expression, to make it work.

var x1 = _context.Users.Where(user => user.IsVerified == true).ToList(); // ok var x2 = _context.Users.Where(user => user.IsVerified).ToList();// ok var x3 = _context.Shops.Where(shop => shop.User.IsVerified == true).ToList();// ok var x4 = _context.Shops.Where(shop => shop.User.IsVerified).ToList();// error

The issue

Exception message:

`Expression of type 'System.Func`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[MyApp.DataAccess.Shops.Shop,System.Collections.Generic.IEnumerable`1[MyApp.DataAccess.Authentication.ApplicationUser]],MyApp.DataAccess.Authentication.ApplicationUser],System.Nullable`1[System.Boolean]]' cannot be used for parameter of type 'System.Func`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[MyApp.DataAccess.Shops.Shop,System.Collections.Generic.IEnumerable`1[MyApp.DataAccess.Authentication.ApplicationUser]],MyApp.DataAccess.Authentication.ApplicationUser],System.Boolean]' of method 'System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[MyApp.DataAccess.Shops.Shop,System.Collections.Generic.IEnumerable`1[MyApp.DataAccess.Authentication.ApplicationUser]],MyApp.DataAccess.Authentication.ApplicationUser]] _Where[TransparentIdentifier`2](System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[MyApp.DataAccess.Shops.Shop,System.Collections.Generic.IEnumerable`1[MyApp.DataAccess.Authentication.ApplicationUser]],MyApp.DataAccess.Authentication.ApplicationUser]], System.Func`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[MyApp.DataAccess.Shops.Shop,System.Collections.Generic.IEnumerable`1[MyApp.DataAccess.Authentication.ApplicationUser]],MyApp.DataAccess.Authentication.ApplicationUser],System.Boolean])'`

Stack trace:

   at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0, Expression arg1)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
   at Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_0`1.<CompileQuery>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Remotion.Linq.QueryableBase`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MyApp.DataAccess.Products.ProductRepository.<GetTotalCount>d__4.MoveNext() in C:\Dev\MyApp\src\MyApp.DataAccess\Products\ProductRepository.cs:line 81
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyApp.Business.Impl.Products.ProductsSearchingService.<SearchForProducts>d__3.MoveNext() in C:\Dev\MyApp\src\MyApp.Business.Impl\Products\ProductsSearchingService.cs:line 33
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyApp.Web.Controllers.Products.ProductsController.<SearchForProducts>d__3.MoveNext() in C:\Dev\MyApp\src\MyApp.Web\Controllers\Products\ProductsController.cs:line 31
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Mvc.Internal.ObjectMethodExecutor.<CastToObject>d__40`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionFilterAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Session.SessionMiddleware.<Invoke>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Session.SessionMiddleware.<Invoke>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()

Further technical details

EF Core version: 1.0.0 Operating system: Windows 10 Visual Studio version: VS 2015

Other details about my project setup:

gisek avatar Jul 20 '16 21:07 gisek

This is already fixed in current bits, closing

maumar avatar Jul 20 '16 21:07 maumar

@maumar When will the fixed version be available?

gisek avatar Aug 01 '16 11:08 gisek

@gisek we don't have the dates fleshed out. The bug has been fixed for the patch release 1.0.1 so we should have them relatively soon.

maumar avatar Aug 01 '16 18:08 maumar

@maumar I've just noticed one more very important thing. This supposedly working example generated the following SQL, which is missing the WHERE statement. So the filtering takes place outside the database.

LINQ

var x3 = _context.Shops.Where(shop => shop.User.IsVerified == true).ToList()

SQL:

SELECT [shop].[Id], [shop].[CreationTime], [shop].[LinkTrackingSuffix], [shop].[ShopName], [shop].[ShopUrl], [shop].[UserId], [shop.User].[Id], [shop.User].[AccessFailedCount], [shop.User].[ConcurrencyStamp], [shop.User].[Email], [shop.User].[EmailConfirmed], [shop.User].[IsVerified], [shop.User].[LockoutEnabled], [shop.User].[LockoutEnd], [shop.User].[NormalizedEmail], [shop.User].[NormalizedUserName], [shop.User].[PasswordHash], [shop.User].[PhoneNumber], [shop.User].[PhoneNumberConfirmed], [shop.User].[SecurityStamp], [shop.User].[TwoFactorEnabled], [shop.User].[UserName]
FROM [Shop] AS [shop]
LEFT JOIN [AspNetUsers] AS [shop.User] ON [shop].[UserId] = [shop.User].[Id]
ORDER BY [shop].[UserId]

Is it the part of the same fixed bug or should I open another issue? So there is not even rough roadmap for the future releases?

gisek avatar Aug 02 '16 18:08 gisek

@gisek this is already tracked here: https://github.com/aspnet/EntityFramework/issues/4588

maumar avatar Aug 02 '16 18:08 maumar

as to the roadmap, unfortunately nothing concrete we can share at the moment. We would rather not share WIP dates or rough estimates in case we slip. Sorry about that. You can track the roadmap here: https://github.com/aspnet/EntityFramework/wiki/Roadmap and here: https://github.com/aspnet/Home/wiki/Roadmap

Those will be updated when we figure out the dates.

maumar avatar Aug 02 '16 19:08 maumar