Description
in "Fetching and storing Data" at https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps#fetching-and-storing-data the docs downplay IQueryable [I agree], but instead recommend "return back an in-memory collection (for example, List) as the result" [I don't agree] ...
If a query concludes with .ToList() or .ToArray(), EF must marshall all the elements into some buffer even if the caller makes no use of any results. Better instead to return the IEnumerable and stream the indiviual elements if/when needed and let the caller decide if/whether to produce a concrete array or list. IMHO any IRepository should likewise concentrate of the neutral IEnumerable rather than List or foo[].
Docs should point to the "Buffering and streaming" at https://learn.microsoft.com/en-us/ef/core/performance/efficient-querying#buffering-and-streaming for a good explanation of how .AsEnumerable() should be used to advantage.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 8e1a443c-c3dd-b865-58b2-0ff0902308ce
- Version Independent ID: d974261f-2544-dee9-f401-e02d715012cb
- Content: Work with data in ASP.NET Core Apps
- Content Source: docs/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps.md
- Product: dotnet-architecture
- Technology: modern-web-apps-azure
- GitHub Login: @ardalis
- Microsoft Alias: wiwagn