Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EfCoreRepository implement IAsyncEnumerable<TEntity> #4807

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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
{
Expand Down Expand Up @@ -195,6 +195,11 @@ public override IQueryable<TEntity> WithDetails(params Expression<Func<TEntity,
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
}