score:1

Accepted answer

For cross join just add another from:

from fees in Session.Query<Fee>()
//cross join:
from feetypes in Session.Query<Session.Query<Fee>()
join ...
join ...
// left join:
join feetypelink in Session.Query<FeeTypeLink>() on 
new {fees.FeeID,feetypes.FeeTypeID} equals new{feetypelink.FeeID,feetypelink.FeeTypeID} 
into gr
from res in gr.DefaultIfEmpty() .....

score:0

You can use this:

from a in ctx.As
join b in ctx.Bs on a.ID equals b.IdOfA //inner join for entities without relationships
join c in ctx.Cs on 1 equals 1 //inner join with constant condition

score:1

Just throw another from in there, since you're not truly "joining" the tables, from a LINQ perspective.

from fees in Session.Query<Fee>()
join feeCategories in Session.Query<FeeCategory>() on fees.FeeCategory.Id equals feeCategories.Id
join feeCompanyType in Session.Query<FeeCompanyType>() on fees.Id equals feeCompanyType.Fee.Id
from feeType in Session.Query<FeeType>()
select ...

score:1

The original query is nonsense and not really doing a cross join

In fact it is equivalent to this

Select various a,b,c,d, and e columns 
From Fee a 
inner Join FeeCategory b on a.CategoryID = b.FeeCategoryID 
inner join FeeCompanyType c on a.FeeID = c.FeeID 
left join FeeTypeLink d on a.FeeID = d.FeeID 
left join Feetype e ON e.FeeTypeID = d.FeeTypeID 

Now you should be able to convert it easily to Linq to SQL. I don't use that much so will leave others to fill in the details. You don't need anything fancy though.


Related Articles