diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs index acc1c3a1bd..87f119016d 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs @@ -26,415 +26,458 @@ namespace Volo.Abp.Domain.Repositories #region Any/All - public static Task AnyAsync( + public static async Task AnyAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AnyAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AnyAsync(queryable, predicate, cancellationToken); } - public static Task AllAsync( + public static async Task AllAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AllAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AllAsync(queryable, predicate, cancellationToken); } #endregion #region Count/LongCount - public static Task CountAsync( + public static async Task CountAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.CountAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.CountAsync(queryable, cancellationToken); } - public static Task CountAsync( + public static async Task CountAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.CountAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.CountAsync(queryable, predicate, cancellationToken); } - public static Task LongCountAsync( + public static async Task LongCountAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.LongCountAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.LongCountAsync(queryable, cancellationToken); } - public static Task LongCountAsync( + public static async Task LongCountAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.LongCountAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.LongCountAsync(queryable, predicate, cancellationToken); } #endregion #region First/FirstOrDefault - public static Task FirstAsync( + public static async Task FirstAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.FirstAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.FirstAsync(queryable, cancellationToken); } - public static Task FirstAsync( + public static async Task FirstAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.FirstAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.FirstAsync(queryable, predicate, cancellationToken); } - public static Task FirstOrDefaultAsync( + public static async Task FirstOrDefaultAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.FirstOrDefaultAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.FirstOrDefaultAsync(queryable, cancellationToken); } - public static Task FirstOrDefaultAsync( + public static async Task FirstOrDefaultAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.FirstOrDefaultAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.FirstOrDefaultAsync(queryable, predicate, cancellationToken); } #endregion #region Last/LastOrDefault - public static Task LastAsync( + public static async Task LastAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.LastAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.LastAsync(queryable, cancellationToken); } - public static Task LastAsync( + public static async Task LastAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.LastAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.LastAsync(queryable, predicate, cancellationToken); } - public static Task LastOrDefaultAsync( + public static async Task LastOrDefaultAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.LastOrDefaultAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.LastOrDefaultAsync(queryable, cancellationToken); } - public static Task LastOrDefaultAsync( + public static async Task LastOrDefaultAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.LastOrDefaultAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.LastOrDefaultAsync(queryable, predicate, cancellationToken); } #endregion #region Single/SingleOrDefault - public static Task SingleAsync( + public static async Task SingleAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SingleAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SingleAsync(queryable, cancellationToken); } - public static Task SingleAsync( + public static async Task SingleAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SingleAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SingleAsync(queryable, predicate, cancellationToken); } - public static Task SingleOrDefaultAsync( + public static async Task SingleOrDefaultAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SingleOrDefaultAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SingleOrDefaultAsync(queryable, cancellationToken); } - public static Task SingleOrDefaultAsync( + public static async Task SingleOrDefaultAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> predicate, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SingleOrDefaultAsync(repository, predicate, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SingleOrDefaultAsync(queryable, predicate, cancellationToken); } #endregion #region Min - public static Task MinAsync( + public static async Task MinAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.MinAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.MinAsync(queryable, cancellationToken); } - public static Task MinAsync( + public static async Task MinAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.MinAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.MinAsync(queryable, selector, cancellationToken); } #endregion #region Max - public static Task MaxAsync( + public static async Task MaxAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.MaxAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.MaxAsync(queryable, cancellationToken); } - public static Task MaxAsync( + public static async Task MaxAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.MaxAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.MaxAsync(queryable, selector, cancellationToken); } #endregion #region Sum - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } - public static Task SumAsync( + public static async Task SumAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.SumAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.SumAsync(queryable, selector, cancellationToken); } #endregion #region Average - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } - public static Task AverageAsync( + public static async Task AverageAsync( [NotNull] this IReadOnlyRepository repository, [NotNull] Expression> selector, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.AverageAsync(repository, selector, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.AverageAsync(queryable, selector, cancellationToken); } #endregion #region ToList/Array - public static Task> ToListAsync( + public static async Task> ToListAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.ToListAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.ToListAsync(queryable, cancellationToken); } - public static Task ToArrayAsync( + public static async Task ToArrayAsync( [NotNull] this IReadOnlyRepository repository, CancellationToken cancellationToken = default) where T : class, IEntity { - return repository.AsyncExecuter.ToArrayAsync(repository, cancellationToken); + var queryable = await repository.GetQueryableAsync(); + return await repository.AsyncExecuter.ToArrayAsync(queryable, cancellationToken); } #endregion