Skip to content

suggest AsEnumerable instead #31985

Closed
@DickBaker

Description

@DickBaker

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions