Repository navigation
Description
I'm getting a runtime error after doing a Count() on a GroupJoin()
Steps to reproduce
var query = _context.Users.GroupJoin(_context.Customers, u => u.Id, c => c.UserId, (u, c) => u);
//Error occurs on this line
int count = query.Count();
Exception message:
Expression of type 'System.Collections.Generic.IEnumerable'1[System.Collections.Generic.IEnumerable'1[MyClass]]' cannot be used for return type 'System.Collections.Generic.IEnumerable`1[System.Int32]'
Stack trace:
at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection'1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable'1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, Boolean tailCall, IEnumerable'1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, ParameterExpression[] parameters) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateExecutorLambdaTResults at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_0'1.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 System.Linq.Queryable.Count[TSource](IQueryable'1 source) at MyProject.Services.User.UserService.SearchUsers(ContactSearchCriteriaDto cscd) in C:\Users\john-luke.laue\repositories\MyProject\src\Services\User\UserService.cs:line 59
Further technical details
EF Core version: 1.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2015
Activity
smitpatel commentedon Jan 27, 2017
Add tests to verify dotnet#7497 is fixed
Add support for translating GROUP BY and OUTER APPLY; optimize transl…
Add support for translating GROUP BY and OUTER APPLY; optimize transl…
Add support for translating GROUP BY and OUTER APPLY; optimize transl…
Add support for translating GROUP BY and OUTER APPLY; optimize transl…
Add support for translating GROUP BY and OUTER APPLY; optimize transl…
Add support for translating GROUP BY and OUTER APPLY; optimize transl…
smitpatel commentedon Feb 15, 2017
Transferring to @maumar ,
In this particular case, we have a group join but there is no selectmany afterwards. We apply count assuming it is safe but it generates query like this:
Which is incorrect since it would count number of rows instead of number of groups. We need to evaluate
Counton client when there is group join without select many.Fix to #6647 - Left Join (GroupJoin) always materializes elements res…
Fix to #6647 - Left Join (GroupJoin) always materializes elements res…
Fix to #6647 - Left Join (GroupJoin) always materializes elements res…
Fix to #6647 - Left Join (GroupJoin) always materializes elements res…
maumar commentedon Mar 23, 2017
Fixed in 03a990c
[-]Error calling Count() after GroupJoin()[/-][+]Query: Error calling Count() after GroupJoin()[/+]