【发布时间】:2020-10-25 02:57:55
【问题描述】:
我正在使用带有 EF 核心的 .net core 3.1 创建一个小型 API。
我正在尝试在我的存储库类中使用 IAsyncEnumerable,但出现错误。
我知道错误是有效的,但谁能告诉我如何在存储库类中使用 IAsyncEnumerable?
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();
}
}
谁能告诉我哪里出错了?
谢谢
【问题讨论】:
标签: c# asp.net-core-webapi asp.net-core-3.1 ef-core-3.1 c#-8.0