When I have a reference to the same table in my select as in my where clause, linq to Nhibernate generates two joins, one for the select and one for the where. i.e.
from child in Session.Query<Child>()
where child.Parent.Name == "Bob"
select new Info
{
ParentAge = child.Parent.Age,
ChildName = child.Name
};
Generates SQL like:
Select this_.Name,
parent1.Age
From Child this_
left join Parent parent1 on child.ParentId = parent1.Id,
Parent parent2
Where child.ParentId = parent2.Id and parent2.Name = 'Bob'
I would have thought I should get SQL more like:
Select this_.Name,
parent1.Age
From Child this_
inner join Parent parent1 on child.ParentId = parent1.Id
Where parent1.Name = 'Bob'
Is there a way to structure the query to get this? Does it matter?