LLBLGen 4.1
Runtime: 4.1.13.1114
Adapter Template, .NET 4.5
SQL Server
I'm trying to create a query using QuerySpec that will result in this SQL:
SELECT [Supporter].[SupporterId]
FROM dbo.Supporter
LEFT JOIN (
Bidder
INNER JOIN dbo.AffiliateType
ON dbo.AffiliateType.AffiliateTypeId = dbo.Bidder.AffiliateTypeId
) ON Supporter.SupporterId = Bidder.BidderID
WHERE Supporter.SupporterId = 0
Note the "nested" or "grouped" join syntax where Bidder is INNER JOINed with AffiliateType, and then that result is LEFT JOINed with Supporter.
I tried creating this query like this:
var qf = new QueryFactory();
var q = qf.Create()
.From(
qf.Supporter.LeftJoin(
qf.Bidder
.InnerJoin(qf.AffiliateType)
.On(AffiliateTypeFields.AffiliateTypeId == BidderFields.AffiliateTypeId)
)
.On(SupporterFields.ClientId == ClientFields.ClientId)
)
.Where(SupporterFields.SupporterId == 0)
.Select(
SupporterFields.SupporterId);
It compiles fine, but it doesn't generate valid SQL:
SELECT [AESOP_ES_DEV].[dbo].[Supporter].[SupporterId]
FROM ( [AESOP_ES_DEV].[dbo].[Supporter]
LEFT JOIN [AESOP_ES_DEV].[dbo].[AffiliateType]
ON [AESOP_ES_DEV].[dbo].[Supporter].[ClientId] = [AESOP_ES_DEV].[dbo].[Client].[ClientId])
WHERE (([AESOP_ES_DEV].[dbo].[Supporter].[SupporterId] = 0 /* @p1 */))
The SQL error is:
Msg 4104, Level 16, State 1, Line 24
The multi-part identifier "AESOP_ES_DEV.dbo.Client.ClientId" could not be bound.
Note that the Client table wasn't included in the JOINs.
Is this supposed to be able to work?
I know that there are a couple of different ways of writing this query without using the nested join syntax, but in my actual query, this syntax leads the SQL optimizer to choose the best query plan, so I'd like to generate the nested join if possible.
Thanks,