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 6616963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:38:48+00:00 2026-05-25T20:38:48+00:00

About half of the examples I see for Linq queries using the Any method

  • 0

About half of the examples I see for Linq queries using the Any method do so by applying it to the results of a Where() call, the other half apply it directly to the collection. Are the two styles always equivalent, or are there cases wheres that they could return different results?

My testing supports the former conclusion; but edge cases aren’t always easy to find.

List<MyClass> stuff = GetStuff();
bool found1 = stuff.Where(m => m.parameter == 1).Any();
bool found2 = stuff.Any(m => m.parameter == 1);
  • 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-25T20:38:49+00:00Added an answer on May 25, 2026 at 8:38 pm

    It comes down to 2 important questions:

    • is it a standard “Where”/”Any” (such as Enumerable.* or Queryable.*), or is it custom? (if the latter, all bets are off)
    • if it is Queryable.*, what is the provider?

    The latter matters hugely. For example, LINQ-to-SQL and LINQ-to-EF behave differently re Single, so I would not assume that they behave identically for Any. A more esoteric provider could do anything. But more: LINQ-to-SQL does different things (re the identity-manager) for Single(predicate) vs Where(predicate).Single (and for First too). In fact, there are 3 different behaviours available in LINQ-to-SQL there depending on 3.5, 3.5SP1, or 4.0.

    Additionally, IIRC LINQ-to-ADO.NET-Data-Services had different (opposite, from memory) support to EF – so (again from memory) while one provider only supported Single(predicate), the other only supported Where(predicate).Single(); it is not a great leap to suggest that Any() could be similarly affected by different providers.

    So: while Any(predicate) and Where(predicate).Any() are semantically equivalent – it is impossible to say if they are actually the same without very detailed information to the context.

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

Sidebar

Related Questions

Many times I find useful code examples on the Internet. About half of the
The examples that Microsoft's Patterns and Practices provides are quite helpful: about a half-dozen
If about half of my views require the same data set, is it appropriate
I have spent about half a day searching for an answer to this question
I've integrated about half a dozen e-payment gateways, from popular ones (like paypal) to
I have an object that contains about half a dozen properties. I expect to
When I run this code, About half-way through the concatenation loop, $xml becomes null
About a half dozen times now, I’ve been doing a regular chore in Visual
I remember reading somewhere on the internets about a half-assed tiny django CMS app,
I am running Ubuntu 9.04 and have done about a half hour worth of

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.