Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Left Outer Join

I'm looking to create a Left outer join Nhibernate query with multiple on statements akin to this:

SELECT 
    * 
FROM [Database].[dbo].[Posts] p
LEFT JOIN 
    [Database].[dbo].[PostInteractions] i
ON 
   p.PostId = i.PostID_TargetPost And i.UserID_ActingUser = 202       

I've been fooling around with the critera and aliases, but I haven't had any luck figuring out how do to this. Any suggestions?

like image 662
Matthew Avatar asked May 03 '10 04:05

Matthew


1 Answers

I actually figured it out. You need to do a check for null

.CreateCriteria("Interactions", "i", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
            .Add(Expression.Or(Expression.Eq("i.ActingUser", user), Expression.IsNull("i.ActingUser")))

this creates a left join on targetpost id and then eliminates all non null/non user interactions.

like image 90
Matthew Avatar answered Nov 18 '22 09:11

Matthew