Skip to content

suggest AsEnumerable instead #31985

Closed

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.

Activity

  1. added a commit that references this issue on Nov 3, 2022
    ed91298
  2. ghost added
    in-pr
    on Nov 3, 2022
  3. added a commit that references this issue on Nov 4, 2022
    f65040d
  4. added
    ⌚ Not Triaged
    and removed
    ⌚ Not Triaged
    on Nov 4, 2022
  5. ghost removed
    in-pr
    on Nov 4, 2022
  6. added a commit that references this issue on Nov 4, 2022
    61e97e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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