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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:37:03+00:00 2026-05-15T19:37:03+00:00

This is the pseudo-SQL I want to generate: SELECT * FROM Table WHERE Column1

  • 0

This is the pseudo-SQL I want to generate:

SELECT * FROM Table WHERE Column1 = @Value1 OR Column2 = @Value2

The problem is, sometimes the second one should not be included. I was hoping to chain together .Where() clauses like so:

var query = context.TableName;
query = query.Where(t => t.Column1 == value1);
if (NeedsToBeIncluded(value2))
  query = query.Where(t => t.Column2 == value2);

Unfortunately, this doesn’t work. .Where() will emit an AND if you chain them together by default. Is there a way to get it to emit an OR?

I’m looking for something along the lines of:

var query = context.TableName;
query = query.Where(t => t.Column1 == value1);
if (NeedsToBeIncluded(value2))
  query = query.OrWhere(t => t.Column2 == value2);

UPDATE
Ok, so my example listed above is too simple. It was merely supposed to be an example that outlines the problem space. Out “in the wild” so to speak, Column1 and Column2 could actually be “CarType” and “OwnerName”, maybe there’s more, maybe there’s less. I just used a simple example to outline the problem because I’m looking to solve a range of domain problems with this chaining-.Where()s together.

  • 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-15T19:37:04+00:00Added an answer on May 15, 2026 at 7:37 pm

    One way is to use LINQKit’s PredicateBuilder.

    Another way is to use a list:

    var values = new List<string> { value1 };
    if (NeedsToBeIncluded(value2)) values.Add(value2);
    query = context.TableName.Where(t => values.Contains(t));
    

    PB is more flexible, but the list will solve the problem in your question. Note that you need EF 4 for Contains.

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

Sidebar

Related Questions

I want to do the following pseudo-SQL: SUM( SELECT a FROM tab WHERE b
I have a pseudo SQL statement like select [orderid], [productname], [price], [productid_FK] from Order
Basically I want to make a pseudo column by which I'll sort. This is
I need help to write this in SQL: I have one table and I
Consider this pseudo code: // an image is initialized UIImage *imagePX = [[UIImage alloc]initWithContentsOfFile:...
Trying to figure out this pseudo code. The following is assumed.... I can only
I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
Here's what I'm trying to do -- this is pseudo code and doesn't work.
Why can't I do something like this in c# (pseudo code follows) Interface1 {
The basic pseudo code looks like this: void myFunction() { int size = 10;

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.