Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:28:32+00:00 2026-05-15T22:28:32+00:00

As we know you can’t add an extra clause like .Where() or .First() to

  • 0

As we know you can’t add an extra clause like .Where() or .First() to a compiled query, because that changes the query and forces a recompile. What I would like to know is which methods can be used to “close” a compiled query.

I know most people use either .AsEnumerable() or .ToList(), but which other methods work as well? Can I use .AsQueryable(), or is this a no-op?

And which is better performance-wise? I know .AsEnumerable() is faster than .ToList(), but if I want an IQueryable, is .AsEnumerable().AsQueryable() better than .ToList()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:28:32+00:00Added an answer on May 15, 2026 at 10:28 pm

    In most cases, AsEnumerable().AsQueryable() is probably what you want, because:

    • By doing an explicit AsEnumerable(), you’re not running the risk of the underlying implementation making AsQueryable() into a no-op, thereby ruining your attempt to close the query. I’m not saying that today’s EF makes AsQueryable() a no-op (as far as I can tell, it doesn’t), only that the behavior– either no-op or transparently call AsEnumerable()– isn’t documented so relying on it isn’t safe.
    • AsEnumerable(), unlike ToList(), doesn’t load your entire resultset in memory in order to query it. This matters a lot with large resultsets. It’s theoretically possible that for smaller resultsets, there could be some advantage to using ToList() (e.g. an optimized ToList() implementation pulls data in big chunks from the underlying provider, while enumeration involves more context switching) but that seems unlikely and hard to depend on across providers and versions, while the large-resultset advantage of AsEnumerable() will live forever.

    The one case where I do like calling ToList() is when I explicitly do want to force a query to execute right now. For example, if I want to catch errors in a query earlier in a method so that I can simplify error handling later, or I want to validate all the underlying data before continuing with the rest of the query. Or if the query is more easily tested when chopped in two. And I’ll never do this, unless I know that my recordset is going to be small, since calling ToList() on a multi-million-row query will kill your RAM.

    To answer your other question, Converting Data Types in the LINQ documentation on MSDN details which LINQ methods force query execution. According to that page, ToArray(), ToDictionary(), ToList(), and ToLookup() all force query execution.

    AsEnumerable(), by contrast, doesn’t force immediate query execution, but does “close” the query (using your term here, not sure if there’s an official term for this). Per http://msdn.microsoft.com/en-us/library/bb335435.aspx:

    the AsEnumerable method can
    be used to hide the custom methods and
    instead make the standard query
    operators available.

    In other words, running AsEnumerable will force all calls like Take() and Where() to use the generic LINQ implementations and not anythign custom which would cause a re-compile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that I know can be done using a subselect, but
I know I can add a icon to the Resources.resx file of a project
This is something I know can be done somehow , because I've done it
I like to know can we define an interface within an interface. like interface
I see that there are two options that I know can be used in
I know I can do most of this by hacking Trac and using Git
I know you can look at the row.count or tables.count, but are there other
I know you can do redirection based on the domain or path to rewrite
I know I can programatically make the taskbar item for a particular window start
I know I can call the GetVersionEx Win32 API function to retrieve the Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.