The following should work:
Booking bookingAlias = null;
var journeyFuture = QueryOver.Of<JourneyFuture>().Where(x=> x.Booking.Id==bookingAlias.Id).
And(x => (!x.IsDriverAssigned && x.Status==JourneyStatusType.Live) || x.Status==JourneyStatusType.CancelRequested
|| x.Status == JourneyStatusType.Modified ||
(x.Status == JourneyStatusType.Live && (!x.IsMetricCalculated || x.Duration==0 || x.Distance==0)))
.Select(x=> x.Booking);
var result = session.QueryOver<Booking>(() => bookingAlias)
.Where(
Restrictions.Or(
Restrictions.Where(() => bookingAlias.Status == BookingStatusType.CancelRequested),
Subqueries.Exists(journeyFuture.DetachedCriteria)))
.List<Booking>();
Basically replace .WithSubquery
with the more powerful Restrictions.Or
and Subqueries.Exists
. I wish there was a way to do this with .WithSubquery
, but I'm not sure there is.
In general, with complex restrictions, you can dip down into the Restrictions
class. The downside to this is that it usually makes your code more complex.