Closed nuclearpidgeon closed 8 years ago
My workaround for the moment is writing the join manually - i.e.
IList<UserGroupAccess> accessPolicies = (
from uga in dcc.UserGroupAccessList
join dg in dcc.DeviceGroups on uga.DeviceGroupId equals dg.Id
join d in dcc.Devices on dg.Id equals d.DeviceGroupId
join ug in dcc.UserGroups on uga.UserGroupId equals ug.Id
join ugm in dcc.UserGroupMembershipList on ug.Id equals ugm.UserGroupId
where ugm.UserId == currentUser.Id && d.Id == id
select uga)
.ToList();
This issue is already fixed in the current bits, most likely fixed by 41ad57ad2f3755c5e35b51d939fab52b489ce738
However the repro uncovered another issue. When the repro is run, the following exception is thrown:
Unhandled Exception: System.InvalidOperationException: The binary operator AndAlso is not defined for the types 'System.Int32' and 'System.String'.
at System.Linq.Expressions.Expression.AndAlso(Expression left, Expression right, MethodInfo method)
at System.Linq.Expressions.Expression.AndAlso(Expression left, Expression right)
at Microsoft.Data.Entity.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression expression) in D:\k\EntityFramework\src\EntityFramework.Relational\Query\ExpressionVisitors\SqlTranslatingExpressionVisitor.cs:line 122
at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
at Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
at Microsoft.Data.Entity.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(Expression expression) in D:\k\EntityFramework\src\EntityFramework.Relational\Query\ExpressionVisitors\SqlTranslatingExpressionVisitor.cs:line 76
at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index) in D:\k\EntityFramework\src\EntityFramework.Relational\Query\RelationalQueryModelVisitor.cs:line 699
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.Data.Entity.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) in D:\k\EntityFramework\src\EntityFramework.Core\Query\EntityQueryModelVisitor.cs:line 528
at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) in D:\k\EntityFramework\src\EntityFramework.Relational\Query\RelationalQueryModelVisitor.cs:line 253
at Microsoft.Data.Entity.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel) in D:\k\EntityFramework\src\EntityFramework.MicrosoftSqlServer\Query\Internal\SqlServerQueryModelVisitor.cs:line 77
at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) in D:\k\EntityFramework\src\EntityFramework.Core\Query\EntityQueryModelVisitor.cs:line 158
at Microsoft.Data.Entity.Storage.Database.CompileQuery[TResult](QueryModel queryModel) in D:\k\EntityFramework\src\EntityFramework.Core\Storage\Database.cs:line 67
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass19_0`1.<CompileQuery>b__0() in D:\k\EntityFramework\src\EntityFramework.Core\Query\Internal\QueryCompiler.cs:line 183
at Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) in D:\k\EntityFramework\src\EntityFramework.Core\Query\Internal\CompiledQueryCache.cs:line 32
at Microsoft.Data.Entity.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query) in D:\k\EntityFramework\src\EntityFramework.Core\Query\Internal\QueryCompiler.cs:line 138
at Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](Expression query) in D:\k\EntityFramework\src\EntityFramework.Core\Query\Internal\QueryCompiler.cs:line 84
at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) in D:\k\EntityFramework\src\EntityFramework.Core\Query\Internal\EntityQueryProvider.cs:line 37
at Remotion.Linq.QueryableBase`1.GetEnumerator()
Fixed in current bits, producing the following sql:
SELECT [uga].[Id], [uga].[AccessPermissions], [uga].[DeviceGroupId], [uga].[UserGroupId], [uga.DeviceGroup].[Id], [uga.UserGroup].[Id]
FROM [UserGroupAccessList] AS [uga]
INNER JOIN [UserGroup] AS [uga.UserGroup] ON [uga].[UserGroupId] = [uga.UserGroup].[Id]
INNER JOIN [DeviceGroup] AS [uga.DeviceGroup] ON [uga].[DeviceGroupId] = [uga.DeviceGroup].[Id]
WHERE @__id_0 IN (
SELECT [dev].[Id]
FROM [Device] AS [dev]
WHERE [uga.DeviceGroup].[Id] = [dev].[DeviceGroupId]
) AND @__currentUserId_1 IN (
SELECT [um].[UserId]
FROM [UserGroupMembership] AS [um]
WHERE [uga.UserGroup].[Id] = [um].[UserGroupId]
)
@maumar, was this fixed in RC2 or after we branched? (milestone should reflect that).
@divega it works in release also
Cool! Moved to the rc2 milestone.
Thanks all for following this up!
I'm building an EF7/MVC5 application at the moment (running beta8 stable on SQLite) with a schema that involves a few join tables/models and am having issues navigating the joins in LINQ.
Quick schema overview:
I am trying to check results in the UserGroupAccess table based off information in the Device and UserGroupMembership tables, which involves basically joining all 5 of the tables. The following code is not working:
It throws the following stack trace:
If I comment out the first part of the Where statement (i.e. only use the
uga.UserGroup.UserMemberships
... test) I get different errors as wellAdditionally I tried commenting out the second part of the Where statement and mucking around with the first part - as soon as I try and do anything past the DeviceGroup<->Device join, I start getting those Nullable errors.
I'm pretty new to EF so not sure whether I'm doing something wrong here or whether this is a bug - I noticed in the roadmap that Property Navigation is still in progress but I figured it would be worth reporting anyway.