While I don't know much about the specific implementation of LINQ 2 NH, I know the library beneath it (re-linq) and LINQ itself, so let me try to help sort out what's broken and what could be done.
The behavior you report is probably unexpected. However, it's not necessarily wrong. The semantics of the translation of LINQ to (ultimately) SQL are largely undefined. Your query would just fail in LINQ 2 objects, so that's not a helpful reference. You could look into LINQ 2 SQL, which is sometimes taken as some kind of reference implementation. However, NH translates LINQ to HQL first, and this translation looks absolutely reasonable. So to change the default behaviour, we would have to either - change the behavior of HQL to use outer joins (unlikely, because there's probably either a good reason or at least a backwards compatibility argument to be made) - translate that LINQ to an explicit outer join in HQL Two workarounds were suggested: using the ternary operator ( ? : ) or using explicit outer joins in LINQ (via DefaultIfEmpty). Both could be supported in LINQ 2 HQL, but I don't know whether this is planned, or for when. See http://blogs.imeta.co.uk/sstrong/archive/2009/12/16/823.aspx You can always offer to help out on the dev list: http://groups.google.com/group/nhibernate-development Cheers, Stefan On Jun 24, 3:15 pm, Kakone <[email protected]> wrote: > I can't to do it by code because most of the time, I will use it with > the Take(x) method. > > For example : > Session.Query<Project>().OrderBy(p.Type.Label).Take(10) > > It's a very simple request, I wonder me if I do something wrong or > it's a bug of LinqNHibernate. > > On 24 juin, 14:44, Oskar Berggren <[email protected]> wrote: > > > > > Maybe there are other solutions, but one way is to do ToList() before > > OrderBy(). The ordering will then happen in your application, instead > > of in SQL. You would need the code from your second try of course, to > > avoid null reference exceptions. > > > /Oskar > > > 2010/6/24 Kakone <[email protected]>: > > > > Hello, > > > > I have a project class with a Type property (it's a nullable reference > > > to a ProjectType entity). > > > > I want to order like this : > > > Session.Query<Project>().OrderBy(p.Type.Label).ToList() > > > When I do this, I don't get the objects where Type property value is > > > null. > > > > So, I tried to write this : > > > Session.Query<Project>().OrderBy(p => p.Type == null ? null : > > > p.Type.Label).ToList() > > > But, in this case, I've got an exception : "No persister for : > > > xx.xxx.EntityBase" > > > > What can I do to get all the objects including those with Type == > > > null ? > > > > Cordially, > > > Kakone. > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "nhusers" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]. > > > For more options, visit this group > > > athttp://groups.google.com/group/nhusers?hl=en.-Masquer le texte des > > > messages précédents - > > > - Afficher le texte des messages précédents -- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
