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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:02:18+00:00 2026-06-03T20:02:18+00:00

The values are all from drop down lists and either can be null or

  • 0

The values are all from drop down lists and either can be null or not.
Need to write a query that will work irrespective if any of the parameter
values are null or not. The below will work/return results only if all the parameters
have values and respectively all .Where statement are true. I am thinking some wild card regex to specify that the null parameters are allowed to match anything. So the more parameters the higher the search accuracy but still work if only some are supplied or none.

   public ActionResult GetResults(string age, string ProgType, string Country)
        {


                    var results = _db.Categories
          .Where(c => c.CatSchema.TypeName == "Programs")
          .Where(c => c.FilterValToCatMaps.Any(fm => fm.FilterValue.Value == age))
          .Where(c => c.FilterValToCatMaps.Any(fm => fm.FilterValue.Value == ProgType))
          .Where(c => c.RootCat.Name == Country)
          .Select(c => c.RootCat);



            return View();
        }
  • 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-03T20:02:19+00:00Added an answer on June 3, 2026 at 8:02 pm

    You can always check for validity in the where clause

    .Where(c => IsInvalidParam() || Check())
    

    Or an example in your case might be

    .Where(c => String.IsNullOrEmpty(Country) || c.RootCat.Name == Country)
    

    Alternativly have a look at the Predicate. Which could lead to a function similar to

    public ActionResult GetResults(List<Predicate<CTYPE>> predicates)
        {
        var results = _db.Categories
          .Where(c => predicates.All(pred => pred(c)))
          .Select(c => c.RootCat);
    
        return View();
        }
    

    Here you only have to include valid predicates in the list, or have the predicates themselves check for the validity of their input and returning true if they cannot filter.

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

Sidebar

Related Questions

I need to count all distinct values from table LDS where status = 'ok'
In C# i need to get all values of a particular property from an
I need to grab all the FIELD and VALUES from a POST. I have
I need to clear the default values from input fields using js, but all
I am trying to use Linq2Sql to return all rows that contain values from
i m trying to create a drop down list that takes values on the
Is there a way to get all possible values from a MySQL enum column?
In C#, is it possible to get all values of a particular column from
Is there a generic way of determining all attributes (and their values) from an
I made up a template to show all the fields and values from a

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.