I'm not familiar with concept of passing in a func. How would I call GetItemsAsync() and just return everything without any conditions at all?
var items = await Respository.GetItemsAsync(d => !d.Completed);
public async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>> predicate)
{
IDocumentQuery<T> query = client.CreateDocumentQuery<T>(
UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId),
new FeedOptions { MaxItemCount = -1 })
.Where(predicate)
.AsDocumentQuery();
List<T> results = new List<T>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync<T>());
}
return results;
}
Just pass in a predicate which is always true, e.g. x => true
.
That relies on the LINQ provider you're using understanding that that means you want everything, of course. Another alternative would be to have another overload of this method that doesn't use a Where
call at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With