2012-08-02 107 views
1

如何转换以下以QueryOver任何提示:NHibernate的QueryOver:伯爵在where子句

var widget = session.Query<Widget>() 
        .Fetch(x => x.NotificationJobs) 
        .Where(x => 
         x.Status == Status.Active && 
         !x.NotificationJobs.Any()) 
        .OrderByDescending(x => x.DateCreated) 
        .Take(1) 
        .SingleOrDefault(); 

想要得到一个没有通知工作的Widget。

回答

0
var widgetWithNoNotificationJob = session.QueryOver<Widget>() 
    .Where(x => x.Status == Status.Active) 
    .OrderBy(x => x.DateCreated).Desc 
    .Left.JoinQueryOver<NotificationJob>(x => x.NotificationJobs) 
     .Where(x => x.NotificationJobId == null) 
    .Take(1) 
    .SingleOrDefault(); 

这将产生SQL与LEFT OUTER JOIN在NotificationJob表并NotificationJob.NotificationJobId WHERE子句IS NULL。

希望这会指出你在正确的方向。