Ejemplo n.º 1
0
    public override async IAsyncEnumerable <TEntity> ListAsync <TKey>(
        Expression <Func <TEntity, bool> >?predicate,
        Expression <Func <TEntity, TKey> >?sort,
        Ordering ordering = Ordering.Descending,
        [EnumeratorCancellation] CancellationToken ct = default)
    {
        predicate = FilteringQuery(predicate);

        var query = BuildQuery(Context, predicate);

        query = ordering switch
        {
            Ordering.Descending when sort != null => query.OrderByDescending(sort),
            Ordering.Ascending when sort != null => query.OrderBy(sort),
            _ => throw new ArgumentOutOfRangeException(nameof(ordering), ordering, null)
        };

        var enumerable = query.AsAsyncEnumerable().WithCancellation(ct);

        await foreach (var entity in enumerable)
        {
            yield return(entity);
        }
    }