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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:47:31+00:00 2026-05-19T02:47:31+00:00

I noticed today that if I do this: var items = context.items.Where(i => i.Property

  • 0

I noticed today that if I do this:

var items = context.items.Where(i => i.Property < 2);
items = items.Where(i => i.Property > 4);

Once I access the items var, it executes only the first line as the data call and then does the second call in memory. However, if I do this:

var items = context.items.Where(i => i.Property < 2).Where(i => i.Property > 4);

I get only one expression executed against the context that includes both where statements. I have a host of variables that I want to use to build the expression for the linq lambda, but their presence or absence changes the expression such that I’d have to have a rediculous number of conditionals to satisfy all cases. I thought I could just add the Where() statements as in my first example above, but that doesn’t end up in a single expression that contains all of the criteria. Therefore, I’m trying to create just the lambda itself as such:

//bogus syntax
if (var1 == "something")
    var expression = Expression<Func<item, bool>>(i => i.Property == "Something);
if (var2 == "somethingElse")
    expression = expression.Where(i => i.Property2 == "SomethingElse");

And then pass that in to the where of my context.Items to evaluate. A) is this right, and B) if so, how do you do it?

EDIT:

IQueryable assessments = assessmentContext.Assessments;
metAssessments = metAssessments.Take(pageSize);

results in

SELECT [Fields] <== edited
FROM [dbo].[Assessment] AS [t0]
INNER JOIN [dbo].[AssessmentComment] AS [t1] ON [t1].[ID] = [t0].[AssessmentID] <== because of load options

Why no top x (as represented by pageSize)?

  • 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-19T02:47:32+00:00Added an answer on May 19, 2026 at 2:47 am

    What query provider are you using? For any reasonable provider, your first example should execute on the source (not in memory) as the conjunction of the two conditions in each of your Wheres.

    As for your question, no, that’s not the right way to proceed to build an Expression manually. Your first definition is fine, but to build a conjunction you need to use Expression.AndAlso.

    People have already wrapped this into a library for your usage. See PredicateBuilder.

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

Sidebar

Related Questions

I noticed today that in D2009 (with update 1), TStringStream.ReadString does not move the
I noticed today that auto-boxing can sometimes cause ambiguity in method overload resolution. The
I've been using Javascript's Date for a project, but noticed today that my code
I noticed today (after ~8 years of happily hacking away at bash) that there
I noticed some code of a colleague today that initialized class variables in the
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
I noticed a new web service today called a Dead man's switch , which
I noticed that Google maps is providing directions in my local language (hungarian) when
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that my Designer.vb file of one of my forms has a lot

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.