public static IFutureValue <TValue> FutureValue <T, TValue>(this IQueryOver <T> query, IDatabaseProvider databaseProvider) { if (databaseProvider.SupportFuture) { return(query.FutureValue <TValue>()); } return(new FunnelWebFutureValue <TValue>(query.SingleOrDefault <TValue>())); }
private int GetCount(IQueryOver <AggregateNodeStatus, AggregateNodeStatus> aggQuery, bool requiresLoadingIds) { if (requiresLoadingIds) { // We can't do a count in the db engine and must load the distinct Ids instead var ids = aggQuery .Select(Projections.Distinct(Projections.Property <AggregateNodeStatus>(x => x.Node.Id))) .Future <Guid>(); return(ids.Distinct().Count()); } int count; if (Helper.SupportsCountDistinct()) { // Set the aggregate to return a count of the distinct NodeIds aggQuery = aggQuery.Select(Projections.CountDistinct <AggregateNodeStatus>(x => x.Node.Id)); count = aggQuery.FutureValue <int>().Value; } else { // SqlCe doesn't support distinct in aggregates, so create a subquery // The ideal subquery for SqlCe would be // select count(*) from (select distinct NodeId ...) // However you can't select from a derived table in NH so we have to do a // select count(*) where exists (select distinct NodeId .. where versionid & statusid match) // We could revert back to the ideal version if we used manual Sql concatenation // Create the distinct NodeId projection aggQuery = aggQuery.Select(Projections.Distinct(Projections.Property <AggregateNodeStatus>(x => x.Node.Id))); // Add some criteria to the inner aggregate query to tie it to the new outer one we'll create for the count AggregateNodeStatus outer = null; aggQuery = aggQuery .Where(x => x.NodeVersion == outer.NodeVersion) .And(x => x.StatusType == outer.StatusType); var outerQuery = Helper.NhSession.QueryOver(() => outer) .Select(Projections.Count <AggregateNodeStatus>(x => x.Node.Id)) .WithSubquery.WhereExists((QueryOver <AggregateNodeStatus>)aggQuery); count = outerQuery.FutureValue <int>().Value; } return(count); }
public TRoot SingleOrDefault() { Build(); return(MainQuery.FutureValue().Value); }