private async Task <T> GetValueSyncOrAsync(bool sync, CancellationToken token = default(CancellationToken)) { T result; if (!_deferred) { CreateCriteriaOrFutures(); } if (_mainFuture != null) { if (_childFutures != null) { foreach (var cq in _childFutures) //we need to force execution: oracle client doesn't support multiple queries (for now) { if (sync) { cq.GetEnumerable(); } else { await cq.GetEnumerableAsync(token); } } } if (sync) { result = _mainFuture.Value; } else { result = await _mainFuture.GetValueAsync(token); } } else { if (sync) { result = _mainCriteria.UniqueResult <T>(); } else { result = await _mainCriteria.UniqueResultAsync <T>(token); } } if (_childNodesInfo != null) { NHUnitHelper.VisitNodes(result, _session, _childNodesInfo); } if (_unproxy) { return(NHUnitHelper.Unproxy(result, _session)); } return(result); }
public async Task <T> GetValueSyncOrAsync(bool sync, CancellationToken token = default(CancellationToken)) { T result; if (_deferred) { if (sync) { result = _mainFuture.GetEnumerable().FirstOrDefault(); } else { var tmp = await _mainFuture.GetEnumerableAsync(token); result = tmp.FirstOrDefault(); } } else { if (sync) { result = await _query.FirstOrDefaultAsync(token); } else { result = _query.FirstOrDefault(); } } if (result != null) { if (_childNodesInfo != null) { NHUnitHelper.VisitNodes(result, _session, _childNodesInfo); } if (_unproxy) { result = NHUnitHelper.Unproxy(result, _session); } } return(result); }