NHibernate Left Outer Join

I am looking to create a Left Nibernate query for an outer join with several statements similar 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 lied to criticism and pseudonyms, but I could not figure out how to do this. Any suggestions?

+5
source share
2 answers

I really understood that. You need to 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 the targetpost id and then eliminates all invalid / non-user interactions.

+12
source

I spent a long time checking all kinds of messages that did not do what I needed, and your post is closest to what I was looking for.

( nHibernate 3) . SQL:

SELECT * 
FROM [Posts] p
LEFT JOIN [PostInteractions] i
   ON p.PostId = i.PostID_TargetPost
WHERE (i.UserID_ActingUser = 202 OR i.UserID_ActingUser IS NULL)

/ , ActingUser 202 .

...

(vb.net):

session.CreateCriteria(Of Posts)("p") _
.CreateCriteria("Interactions", "i", _
                NHibernate.SqlCommand.JoinType.LeftOuterJoin, _
                Expression.Eq("i.ActingUser", user))

CreateCriteria "withClause". , , , .

, - ...

, nHibernate- ( ): http://ayende.com/blog/4023/nhibernate-queries-examples

!

0

All Articles