Browse Source

Merge pull request #4807 from abpframework/maliming/IAsyncEnumerable

Make EfCoreRepository implement IAsyncEnumerable<TEntity>
pull/4813/head
Alper Ebicoglu 6 years ago
committed by GitHub
parent
commit
4a973c2ee0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  2. 24
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests.cs

7
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -15,7 +15,7 @@ using Volo.Abp.Guids;
namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
{
public class EfCoreRepository<TDbContext, TEntity> : RepositoryBase<TEntity>, IEfCoreRepository<TEntity>
public class EfCoreRepository<TDbContext, TEntity> : RepositoryBase<TEntity>, IEfCoreRepository<TEntity>, IAsyncEnumerable<TEntity>
where TDbContext : IEfCoreDbContext
where TEntity : class, IEntity
{
@ -195,6 +195,11 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return query;
}
public IAsyncEnumerator<TEntity> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return DbSet.AsAsyncEnumerable().GetAsyncEnumerator(cancellationToken);
}
protected virtual void CheckAndSetId(TEntity entity)
{
if (entity is IEntity<Guid> entityWithGuidId)

24
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<AbpEntityFrameworkCoreTestModule>
{
[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);
});
}
}
}

Loading…
Cancel
Save