From 4c1d2f89574fa60bb1d75a6bb3398a793579ebc1 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Sun, 19 Jul 2020 23:01:23 +0800 Subject: [PATCH 1/2] Make EfCoreRepository implement IAsyncEnumerable Resolve #4806 --- .../EntityFrameworkCore/EfCoreRepository.cs | 7 +++++- .../Repositories/Repository_Basic_Tests.cs | 24 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 29f37267042..a56430f8640 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -15,7 +15,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore { - public class EfCoreRepository : RepositoryBase, IEfCoreRepository + public class EfCoreRepository : RepositoryBase, IEfCoreRepository, IAsyncEnumerable where TDbContext : IEfCoreDbContext where TEntity : class, IEntity { @@ -195,6 +195,11 @@ public override IQueryable WithDetails(params Expression GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken()) + { + return DbSet.AsAsyncEnumerable().GetAsyncEnumerator(cancellationToken); + } + protected virtual void CheckAndSetId(TEntity entity) { if (entity is IEntity entityWithGuidId) diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests.cs index bfa6b8532d7..3d5d7b656b9 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests.cs @@ -1,9 +1,31 @@ -using Volo.Abp.TestApp.Testing; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Shouldly; +using Volo.Abp.TestApp.Testing; +using Xunit; namespace Volo.Abp.EntityFrameworkCore.Repositories { public class Repository_Basic_Tests : Repository_Basic_Tests { + [Fact] + public async Task EFCore_QueryableExtension_ToListAsync() + { + await WithUnitOfWorkAsync(async () => + { + var persons = await PersonRepository.ToListAsync(); + persons.Count.ShouldBeGreaterThan(0); + }); + } + [Fact] + public async Task EFCore_QueryableExtension_CountAsync() + { + await WithUnitOfWorkAsync(async () => + { + var count = await PersonRepository.CountAsync(); + count.ShouldBeGreaterThan(0); + }); + } } } From 51f765c84c2fa23fc1247338eb1ccbead89ec290 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Mon, 20 Jul 2020 16:04:47 +0800 Subject: [PATCH 2/2] Update framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Halil İbrahim Kalkan --- .../Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index a56430f8640..4f2ce6b4347 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -195,7 +195,7 @@ public override IQueryable WithDetails(params Expression GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken()) + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { return DbSet.AsAsyncEnumerable().GetAsyncEnumerator(cancellationToken); }