Hello,
I have the following data model (see the atachment); I need to get to all records in PortfolioPermission_SecurityGroup for user with loign name ‘john’ and Company ID = 61.
This is my code:
qg = qg.WithPath(new PathEdge<SecurityGroupEntity>(PortfolioPermissionSecurityGroupEntity.PrefetchPathSecurityGroup,
new PathEdge<SecurityUserSecurityGroupEntity>(SecurityGroupEntity.PrefetchPathSecurityUserSecurityGroups,
new PathEdge<SecurityUserEntity>(SecurityUserSecurityGroupEntity.PrefetchPathSecurityUser))));
qg = qg.Where(d => d.CompanyId == 61);
qg = qg.Where(d => d.SecurityGroup.SecurityUserSecurityGroups.Any(q => q.SecurityUser.LoginName == "john"));
The generated SQL gives an error (I have replaced @LoginName2 and @CompanyId1 with actual values for convenience):
SELECT DISTINCT
[LPLA_1].[SecurityGroup_ID] AS [SecurityGroupId],
[LPLA_1].[Company_ID] AS [CompanyId],
[LPLA_1].[SecurityRights_ID] AS [SecurityRightId]
FROM [dbo].[PortfolioPermission_SecurityGroup] [LPLA_1]
WHERE ( ( ( ( ( [LPLA_1].[Company_ID] = 61)) AND
EXISTS (SELECT [LPA_L2].[SecurityGroup_ID] AS [SecurityGroupId]
FROM ( [dbo].[SecurityUser] [LPA_L1] INNER JOIN
[dbo].[SecurityUser_SecurityGroup] [LPA_L2] ON [LPA_L1].[SecurityUser_ID]=[LPA_L2].[SecurityUser_ID])
WHERE ( [LPLA_2].[SecurityGroup_ID] = [LPA_L2].[SecurityGroup_ID] AND
( [LPA_L1].[SecurityUser_LoginName] = 'john'))))))
The error is:
The multi-part identifier "LPLA_2.SecurityGroup_ID" could not be bound.
If I replace the LPLA_2 with LPLA_1 (as follow) the code works;
SELECT DISTINCT
[LPLA_1].[SecurityGroup_ID] AS [SecurityGroupId],
[LPLA_1].[Company_ID] AS [CompanyId],
[LPLA_1].[SecurityRights_ID] AS [SecurityRightId]
FROM [dbo].[PortfolioPermission_SecurityGroup] [LPLA_1]
WHERE ( ( ( ( ( [LPLA_1].[Company_ID] = 61)) AND
EXISTS (SELECT [LPA_L2].[SecurityGroup_ID] AS [SecurityGroupId]
FROM ( [dbo].[SecurityUser] [LPA_L1] INNER JOIN
[dbo].[SecurityUser_SecurityGroup] [LPA_L2] ON [LPA_L1].[SecurityUser_ID]=[LPA_L2].[SecurityUser_ID])
WHERE (
/* -> */ [LPLA_1].[SecurityGroup_ID] /* <- */ = [LPA_L2].[SecurityGroup_ID] AND
( [LPA_L1].[SecurityUser_LoginName] = 'john'))))))
Now the question: How can I work wround this and can I expect this to be fixed in the next version.
Thanks a lot
Kiril