❔ How do IAsyncEnumerable gets the data from the database
Do you know if IAsyncEnumerable loads all the data from the database before streaming it to the application, or does it directly retrieve a stream of data record by record from the database itself?
I am a bit uncertain about this particular scenario. Here's an example:
public class MyEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
await foreach (var entity in dbContext.MyEntities.AsAsyncEnumerable())
{
Console.WriteLine($"Id: {entity.Id}, Name: {entity.Name}");
}
2 Replies
IAsyncEnumerable<T>
is a stream
it does not preload everything from the database before handing control to the caller, that's the entire point
it's the logical equivalent of a DataReaderWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.