public QueryableSingleRepository([NotNull] IQueryableSingle <TNav> singleItemQuery) { if (singleItemQuery == null) { throw new ArgumentNullException(nameof(singleItemQuery)); } SingleItemQuery = singleItemQuery; }
public IRestResource GetFullResource(IDeferredItem <TItem> item, IDataTransaction dataTransaction) { //TNav navItem = _navTools.NavExpression.Compile().Invoke(item.LoadedItem); //var itemRepository = new LoadedItemRepository<TNav>(navItem); IQueryableSingle <TNav> navigationQuery = item.Query.Select(_navTools.NavExpression).SingleDefferred(); var itemRepository = new QueryableSingleRepository <TNav>(navigationQuery); var eventWrapper = new DataEventWrapper <TNav>(dataTransaction, itemRepository); eventWrapper.TryWrapEvents(_navTools.RepoEvents); var context = new FullEngineContext <TNav>(eventWrapper.Transaction, eventWrapper.Repository, _engineSubContext); var deferredNavItem = new RepositoryDeferredItem <TNav>(itemRepository); return(new EngineRestItem <TNav>(context, deferredNavItem)); }
/// <summary> /// Loads a single scalar field reader from a single <see cref="itemQuery"/>. /// </summary> public static async Task <object> LoadScalarValueAsync <TItem>([NotNull] IFieldReader <TItem> reader, IQueryableSingle <TItem> itemQuery, ForEachAsyncDelegate <object> forEachAsync) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } ParameterExpression itemPram = Expression.Parameter(typeof(TItem), "itm"); Expression selectExpression = reader.GetSelectExpression(itemPram); IQueryable selectScalarOnlyQuery = ExpressionTreeHelpers.GetSelectExpressionQuery(itemQuery, itemPram, selectExpression); object loadedValue = await ItemQueryHelper.SingleOrCreateAsync(selectScalarOnlyQuery, forEachAsync, () => throw new ParentItemNotFoundException()); if (reader.Replacer != null) { await reader.Replacer.LoadAsync(itemQuery); return(reader.Replacer.GetReplacement(loadedValue)); } return(loadedValue); }