/// <summary> /// Find one from the repository. This is the equivalent of the Repository's Find() method. /// </summary> /// <param name="context"></param> /// <returns></returns> public IDataLoaderResult <Model> QueueFind <Model, PrimaryKey>(Expression <Func <Model, bool> > where, string loaderKey = null) where Model : class { var thisRequest = new DataLoaderRequest <Model, PrimaryKey> { Where = where, OrderBy = null, OrderByDescending = false, ThenBy = null, ThenByDescending = false, Skip = 0, Take = 1 }; // Get or add a batch loader with the dataLoaderName. // The loader will group the calls to the repository together and split the results back out again to return them. var loader = _accessor.Context.GetOrAddBatchLoader <DataLoaderRequest <Model, PrimaryKey>, Model>( loaderKey ?? GetDefaultLoaderKey <Model>("Find"), async requests => { var data = await LoadData(requests); var ret = data.ToDictionary( item => item.Key, item => item.Value.FirstOrDefault() ); return(ret); } ); // Add this request to the pending requests to fetch // The task will complete once the the data loader returns with the batched results return(loader.LoadAsync(thisRequest)); }
/// <summary> /// Find multiple from the repository. This is the equivalent of the Repository's FindAll() method. /// </summary> /// <param name="context"></param> /// <returns></returns> public IDataLoaderResult <IEnumerable <Model> > QueueFindAll <Model, PrimaryKey>(Expression <Func <Model, bool> > where, Expression <Func <Model, object> > orderBy = null, bool orderByDescending = false, Expression <Func <Model, object> > thenBy = null, bool thenByDescending = false, int skip = 0, int?take = null, string loaderKey = null) where Model : class { var thisRequest = new DataLoaderRequest <Model, PrimaryKey> { Where = where, OrderBy = orderBy, OrderByDescending = orderByDescending, ThenBy = thenBy, ThenByDescending = thenByDescending, Skip = skip, Take = take }; // Get or add a batch loader with the dataLoaderName. // The loader will group the calls to the repository together and split the results back out again to return them. var loader = _accessor.Context.GetOrAddBatchLoader <DataLoaderRequest <Model, PrimaryKey>, IEnumerable <Model> >( loaderKey ?? GetDefaultLoaderKey <Model>("FindAll"), async requests => { var ret = await LoadData(requests); return(ret); } ); // Add this request to the pending requests to fetch // The task will complete once the the data loader returns with the batched results return(loader.LoadAsync(thisRequest)); }