I am creating a small API using .net core 3.1 with EF core.
And I am trying to use IAsyncEnumerable in my repository class but I am getting error.
Error is valid I know but can anybody tell me how to use IAsyncEnumerable in repository class ?
StateRepository.cs
public class StateRepository : IStateRepository
{
public StateRepository(AssetDbContext dbContext)
: base(dbContext)
{
}
public async Task<State> GetStateByIdAsync(Guid id)
=> await _dbContext.States
.Include(s => s.Country)
.FirstOrDefaultAsync(s => s.StateId == id);
public async IAsyncEnumerable<State> GetStates()
{
// Error says:
//cannot return a value from iterator.
//Use the yield return statement to return a value, or yield break to end the iteration
return await _dbContext.States
.Include(s => s.Country)
.ToListAsync();
}
}
Can anybody tell me where I am going wrong ?
Thanks