谓词返回所有项目

时间:2019-02-03 15:54:04

标签: c#

我对传递函子的概念不熟悉。 我将如何调用GetItemsAsync()并只返回所有内容而没有任何条件?

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;
    }

1 个答案:

答案 0 :(得分:6)

只需传入一个始终为真的谓词,例如x => true

这取决于您使用的LINQ提供程序,这当然意味着您需要一切。另一种选择是使此方法的另一个重载完全不使用Where调用。