This is a simplification of query I’m trying to get working:
from r in Risk
from rl in r.RiskLikelihoodSeverities.DefaultIfEmpty()
select new
{
r.WRNumber,
r.WRPeriod,
rl.InitialLikelihoodID,
r.RiskReview.Title,
}
I’m after all Risks and their RiskReview if they have one. RiskReview is a descendent of WorkRequest.
The query produces this sql:
DECLARE @p1 VarChar(4); SET @p1='RR'
DECLARE @p2 VarChar(4); SET @p2='Abst'
DECLARE @p3 VarChar(4); SET @p3='ORR'
DECLARE @p4 VarChar(4); SET @p4='FRR'
DECLARE @p5 VarChar(4); SET @p5='HRR'
DECLARE @p6 VarChar(4); SET @p6='SRR'
DECLARE @p7 VarChar(4); SET @p7='RR'
DECLARE @p8 VarChar(4); SET @p8='Abst'
DECLARE @p9 VarChar(4); SET @p9='ORR'
DECLARE @p10 VarChar(4); SET @p10='FRR'
DECLARE @p11 VarChar(4); SET @p11='HRR'
DECLARE @p12 VarChar(4); SET @p12='SRR'
SELECT [LPA_L1].[WR_Number] AS [WRNumber],
[LPA_L1].[WR_Period] AS [WRPeriod],
[LPA_L2].[Initial_Likelihood_ID] AS [InitialLikelihoodID],
[LPA_L3].[Title]
FROM
(( [AQD].[rm_Risk] [LPA_L1]
LEFT JOIN
[AQD].[rm_Risk_Likelihood_Severity] [LPA_L2] ON [LPA_L1].[Risk_No]=[LPA_L2].[Risk_No])
LEFT JOIN
[AQD].[qaoc_Work_Request] [LPA_L3] ON [LPA_L3].[WR_Number]=[LPA_L1].[WR_Number] AND [LPA_L3].[WR_Period]=[LPA_L1].[WR_Period] AND [LPA_L3].[WR_Type]=[LPA_L1].[WR_Type] AND ( ( [LPA_L3].[WR_Type] IN (@p1,
@p2,
@p3,
@p4,
@p5,
@p6))))
WHERE
( ( ( [LPA_L3].[WR_Type] IN (@p7,
@p8,
@p9,
@p10,
@p11,
@p12))))
Which includes a pesky where clause which excludes risks with a null WR_Type (i.e. no risk reviews). If I remove the where clause from the SQL and run it I get the results I want.
Question is: How do I get rid of the where clause? And it seems totally redundant given that it is in the join as well.