OrderBy generates an inner join instead a left join

Description

If I do this :
Session.Query<Project>().OrderBy(p.Type.Label).ToList()
an inner join is generated (due to the reference to p.Type). The expected result is a left join, otherwise, we don't receive any results where p.Type is null.

More comments on this thread :
http://groups.google.com/group/nhibernate-development/browse_thread/thread/3cf5f441c4392dde/0b4fa0951414f932

Environment

None

Activity

Stéphane Mitermite December 2, 2010 at 1:11 AM

I don't understand your comment. In my case, I have a Project class like this :
public class Project : Entity
{
public string Description { get; set; }
public ProjectType Type { get; set; }
}

and a ProjectType classe like this :
public class ProjectType : Entity
{
public string Label { get; set; }
}

I want to select all the projects order by Type.Label :
Session.Query<Project>().OrderBy(p => p.Type.Label).ToList();

The generated SQL code is :
select p.id, p.description, p.projectTypeId
from Project p, ProjectType pt
where p.projectTypeId = pt.projectTypeId
order by pt.label asc;

As an inner join is generated, we don't receive any results where p.Type is null.
We think (http://groups.google.com/group/nhibernate-development/browse_thread/thread/3cf5f441c4392dde/0b4fa0951414f932) that it should be :
select p.id, p.description, p.projectTypeId
from Project p
left join ProjectType pt on p.projectTypeId = pt.projectTypeId
order by pt.label asc;

Patrick Earl December 1, 2010 at 7:54 PM

I tried this on a self-join and no order by clause was generated at all.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created November 8, 2010 at 6:40 AM
Updated March 8, 2011 at 11:28 AM
Resolved January 17, 2011 at 4:00 AM
Who's Looking?