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

  • SEARCH
  • Home
  • 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 9181299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:16:45+00:00 2026-06-17T18:16:45+00:00

I was wondering if I do something like: var results = source.Where(c => c.Name

  • 0

I was wondering if I do something like:

var results = source.Where(c => c.Name == "Whatever");

is there any way to check if the query returned anything before calling Count() or ToList() ? I know Where() executes lazily.

The data set returned might be huge and calling the above methods is quite time consuming.

results is never NULL either…

Thank you.

  • 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-06-17T18:16:47+00:00Added an answer on June 17, 2026 at 6:16 pm

    Since you just want to know if it’s worthwhile to get the full result set this is never worth doing.

    There are only two situations here:

    1. There are no results for your query. In this case, the query to check how many results there are will take exactly as long to execute, and return exactly as much information, as the real query. You gain nothing (but also lose nothing) in this case.

    2. There is at least one result to your query. In this case you need to go back and execute the real query. The net result is that you spent just as much time as you would have by not checking first, but you also have the added cost of checking if there are results. That check means a round trip to the database, which is a non-trivial amount of time.

    If you want to know if a query will contain any items it’s possible. (Just use the Any extension method.) However, it’s only beneficial if you don’t need to know what the actual items are regardless of what the result of Any is.

    It’s also worth noting, as lazyberezovsky did in his answer, that you also need to consider the race condition where the results of the query change after you call Any.

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

Sidebar

Related Questions

Given something like this: var results = theElement.Element(Blah).Element(Whatever).Elements(Something); Is there an elegant way to
Came across something like this today, and was wondering if there was an equivalent
I'm wondering if there is something like Hotswap/HotDelpoy/JRebel (known from Java World) in .NET
I was wondering what is the best way to convert something like haaaaapppppyyy to
I'm exploring the power of regular expressions, so I'm just wondering if something like
I was wondering if it is always necessary to use something like is_array() before
I was wondering if it was possible to do something like this. I want
I have been wondering whether there is any code out there that enables representing
I'm wondering if Python has anything like the C# anonymous classes feature. To clarify,
I was wondering: is there a way to make Objective-C support a multi-variable switch

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.