Is this the correct way to use foreach loops whist using async ? Is there a better more efficient way? IAsyncEnumerable? (Ignore the fact that the two tables could be joined together this is a simple example)
public async Task<IList<ContactAndAccounts>> GetAll()
{
var accounts = await _dbContext.Account.Where(x => x.Name == "Amazing").ToListAsync();
foreach(var account in accounts)
{
accounts.Contacts = await GetContact(account.Id);
}
return accounts;
}
public async Task<IList<contact>> GetContact(Guid id)
{
return await _dbContext.Contact.Where(x => x.AccountLinkId = id).ToListAsync();
}