2009-12-19 81 views
0

是否可以在不使用CreateSQLQuery的情況下在NHibernate中執行此操作。最好用Linq To Nhibernate。最大的問題是我該怎麼做,而不是主鍵?是否可以在不使用CreateSQLQuery的情況下在NHibernate中執行此操作?

SELECT DISTINCT calEvent.* From CalendarEvent as calEvent 
LEFT JOIN UserChannelInteraction as channelInteraction on channelInteraction.ChannelToFollow_id = calEvent.Channel_id 
LEFT JOIN UserCalendarEventInteraction as eventInteraction on eventInteraction.CalendarEvent_id = calEvent.Id 
LEFT JOIN UserChannelInteraction as eventInteractionEvent on eventInteractionEvent.UserToFollow_id = eventInteraction.User_id 
WHERE (calEvent.Channel_id = @intMainChannelID 
OR channelInteraction.User_id = @intUserID 
OR eventInteraction.User_id = @intUserID 
OR (eventInteractionEvent.User_id = @intUserID AND eventInteraction.Status = 'Accepted')) 
AND calEvent.StartDateTime >= @dtStartDate 
AND calEvent.StartDateTime <= @dtEndDate 
ORDER BY calEvent.StartDateTime asc 

回答

0

你可以任意連接使用Theta joins。 Theta連接是笛卡爾積,所以它會導致所有可能的組合,然後可以進行過濾。

在NHibernate中,你可以執行THETA風格加入這樣的(HQL):

from Book b, Review r where b.Isbn = r.Isbn 

然後,您可以添加要,命令結果的任何過濾條件和一切你可能想這樣做。

from Book b, Review r where b.Isbn = r.Isbn where b.Title = 'My Title' or r.Name = 'John Doe' order by b.Author asc 

Here is an article約THETA加入Hibernate中(不NHibernate的,但它仍然是相關的)。

但是,由於theta連接是笛卡爾積,因此在使用該方法執行三連接查詢之前,您可能需要考慮兩次並進行一些性能測試。

相關問題