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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:14:42+00:00 2026-06-10T20:14:42+00:00

Let’s say we have a description field on my form with optional check boxes.

  • 0

Let’s say we have a description field on my form with optional check boxes. The check boxes represent which fields to search when doing the lookup. Right now I have a matrix of look ups that call their unique version of where clause. It works but I think it smells a bit.

Here is an excerpt

    // Look for part numbers decide how many fields to search and use that one.
    // 0 0 X
    if (!PartOpt[0] && !PartOpt[1] && PartOpt[2])
    {
     query = query.Where(p => (p.PartNumAlt2.Contains(partSearchRec.inventory.PartNum)));
    }
    // 0 X 0
    if (!PartOpt[0] && PartOpt[1] && !PartOpt[2])
    { 
      query = query.Where(p => (p.PartNumAlt.Contains(partSearchRec.inventory.PartNum)));
    }
    // 0 X X
    if (!PartOpt[0] && PartOpt[1] && PartOpt[2])
    {
      query = query.Where(p => (p.PartNumAlt.Contains(partSearchRec.inventory.PartNum)
        || p.PartNumAlt2.Contains(partSearchRec.inventory.PartNum)));
    }
    // X 0 0
    if (PartOpt[0] && !PartOpt[1] && !PartOpt[2])
    {
      query = query.Where(p => (p.PartNum.Contains(partSearchRec.inventory.PartNum)));
    }
     . . .

This goes on for a while and seems to be prone to coding errors. In each case we are looking for the same information in any of the selected fields. If I was doing this in SQL I could simply build up the WHERE clause as needed.

  • 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-06-10T20:14:43+00:00Added an answer on June 10, 2026 at 8:14 pm

    Once again I rubber ducked my way to an answer. Rather than throw the question away, here is what I came up with. Is it efficient?

    if (partSearchRec.optPartNum || partSearchRec.optAltPartNum1 || partSearchRec.optAltPartNum2)
    {
      query = query.Where(p => (
           (partSearchRec.optPartNum && p.PartNum.Contains(partSearchRec.inventory.PartNum))
        || (partSearchRec.optAltPartNum1 && p.PartNumAlt.Contains(partSearchRec.inventory.PartNum))
        || (partSearchRec.optAltPartNum2 && p.PartNumAlt2.Contains(partSearchRec.inventory.PartNum))));
    }
    

    Basically if any of the check boxes are set we will execute the query. Each line of the query will be processed only if the check box was checked. If the left side of an AND is false it doesn’t process the right.

    This is an aera that Delphi’s with statement would be handy. I also learned that you can’t use an array inside the LINQ statement.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have a method in java, which looks up a user in
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let me explain best with an example. Say you have node class that can
Let's say I have a table with a Color column. Color can have various
Let's say that I have a SQLite database that I create in a separate
Let's say I have thousands of users and I want to make the passwords
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis

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.