liveBook · Manning

IAsyncEnumerable<T>

As explained in .NET in Action, Second Edition

IAsyncEnumerable is a .NET interface for asynchronously enumerating a sequence whose elements may become available over time.

IAsyncEnumerable<T> asynchronously enumerates results as they become available. In an ASP.NET Core action, it can begin sending database records without waiting for the complete query result. section 5.4.1

Compared with IEnumerable, it supports slow queries or large result sets by avoiding a fully prepared response. ASP.NET Core serializes the enumerable as a JSON array and finishes when the connection closes. section 5.4.1

Streaming books from a controller

A CatalogController can return IAsyncEnumerable<Book> from its GET method while querying CatalogContext. Optional filtering and Entity Framework Core query configuration remain part of the action. section 5.4.1

How .NET in Action, Second Edition covers it

How deep it goes
Explains synchronous comparison, response timing, JSON serialization, and connection completion, but not enumerator internals.
Examples
Uses a CatalogController GET endpoint returning IAsyncEnumerable<Book> from a filtered Entity Framework Core query.
What it assumes
Assumes familiarity with IEnumerable, ASP.NET Core controllers, and database queries.
What you can do after
Apply it via ASP.NET Core to stream database records without preparing the complete JSON response first.
How it connects
Connects asynchronous enumeration with IEnumerable, ASP.NET Core, Entity Framework Core, JSON, and HTTP responses.

Also explained in

Compare how 2 books explain IAsyncEnumerable<T> →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.