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

Noticed this today when a patch was submitted with the following line: lblCompletionTime.Text =
I noticed today that delete will not work in chrome when this popup blocker
Somehow I never noticed until today that C++ supports nested classes. This surprised me
Noticed this today. Given that a file named existing exists in the PWD of
I only just noticed this feature today! s={1,2,3} #Set initialisation t={x for x in
I noticed something odd today. I have an application that writes/read data to a
I was playing around with some Javascript snippets today and noticed that this code
I noticed today that I can't use * to pass width or precision arguments
I am relatively new to C#, and I noticed something interesting today that I
Today I noticed that now when I Ctrl+/ one or more lines in Eclipse

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.