NHibernate的QueryOver:伯爵在where子句
问题描述:
如何转换以下以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。
答
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。
希望这会指出你在正确的方向。