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

The Archive Base Latest Questions

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

It looks like I can write a where x.a==1 && x.b==1 as where x.a==1

  • 0

It looks like I can write a where x.a==1 && x.b==1 as

where x.a==1
where x.b==1

As I understand the latter turns into .Where(x => x.a == 1).Where(x => x.b ==1), but how does this translate to DB? Which would be better in terms of optimization? I can always look at the executed query from profiler but that would hardly be a generalization but more like a single empirical observation, which I don’t want to rely on.

Going through System.Linq namespace with reflector is another option but then we would miss the chance to save many people from spending time on the same thing. I’ll do it if I don’t get any answers.

  • 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-12T21:15:29+00:00Added an answer on May 12, 2026 at 9:15 pm

    Ok here are my findings after going through Reflector output for a while. LINQ-to-Objects combine the consecutive where predicates when using WhereArrayIterator or WhereListIterator causing it to ALMOST behave like && operator, but not as exactly:

    When you use x.a==1 && x.b==1 the where clause translates into a Func<TSource, bool> looking like this:

    bool daspredicate(TSource x)
    {
        return x.a==1 && x.b==1
    }
    

    However, when you use consecutive Where clauses there is a slight performance penalty, at least from non-JITted IL-aspect. Here is how code looks like after combining:

    bool predicate1(TSource x)
    {
         return x.a==1;
    }
    bool predicate2(TSource x)
    {
         return x.b==1;
    }
    bool daspredicate(TSource x)
    {
        return predicate1(x) && predicate2(x);
    }
    

    As you can see this involves additional function call overhead. This can be quite expensive unless JIT inlines the functions. I’m sure it does a good job at it but we now know JIT’s job becomes much easier if we combine our Where statements ourselves, unless necessary.

    On the SQL-side of things though, the queries are the same. Even before execution, debugger evaluates the query object into the same SQL statement. I couldn’t go too far in Linq namespace because things seemed much more complex, but since queries are the same, there should be no penalty unlike LINQ-to-objects example above.

    EDIT: I’ve seen instances where multiple where statements resulting in nested sub-queries on SQL server. I think it’s better to stick to single where statements whenever you can to be on the safe side.

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

Sidebar

Related Questions

In android the Toggle buttons are looks like below - Can we modify this
I have something that looks like this: As you can see, Blambo is a
Currently my tableview looks like this: as you can see, cell.textLabel and cell.detailTextLable both
My string looks like this $string_value = /hello/world/this/feels/great/ how can I trim world and
I have an xml datasource which looks like this: <dsQueryResponse> <Department> <Rows> <Row dept=HR
I'm reading a XML file with dom4j. The file looks like this: ... <Field>&#13;&#10;
I'm trying to write a validation method. Eg: for double it looks like this:
It looks like you can only have one lifecycle policy per plugin type in
I have a simple example ( SVG source ) looks like you can see
It looks like std::cout can't print member function's address, for example: #include <iostream> using

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.