1

有关如何将以下内容转换为 QueryOver 的任何提示:

 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();

想要获得没有通知作业的小部件。

4

1 回答 1

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();

这将在 NotificationJob 表上生成带有 LEFT OUTER JOIN 的 SQL,以及带有 NotificationJob.NotificationJobId IS NULL 的 WHERE 子句。

希望这将为您指明正确的方向。

于 2012-08-03T07:38:45.297 回答