Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predicate return all items

Tags:

c#

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;
    }
like image 691
Jason Jay Avatar asked Oct 18 '25 07:10

Jason Jay


1 Answers

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.

like image 129
Jon Skeet Avatar answered Oct 20 '25 22:10

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!