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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:14:20+00:00 2026-05-13T22:14:20+00:00

I took a look at this answer and it goes in part to solving

  • 0

I took a look at this answer and it goes in part to solving my issue.

However, what I need is the following.

Given I have an object;

Product
  string code
  List<suitability> items

and then i have this object;

Suitability
  key
  value

Each Product has a variable amount of [items] and the key/value pairs differ from product to product.

When searching I am given a list of Suitability objects. I now need to search all the products that contain (all) of the supplied suitability objects.

So for example a product may have dental = true and therapies = true.

I may get a request for all products that have dental = true and therapies = false.

  • 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-13T22:14:21+00:00Added an answer on May 13, 2026 at 10:14 pm

    Using PredicateBuilder (from the authors of LinqPad) you can build up a query from a set of conditions not known at compile time. The following should be sufficient:

    var predicate = PredicateBuilder.True<Product>();
    
    foreach (Suitability criteria in searchCriteria)
    {
        string tempKey = criteria.Key;
        string tempValue = criteria.Value;
        predicate = predicate.And(p => 
                         p.Items.Any(s => s.Key == tempKey && s.Value == tempValue));
    }
    
    return dataContext.Products.Where(predicate.Compile());
    

    UPDATE: Heres some sample code that I have tested which works using an IEnumerable as the source, the resulting set productsResult contains the first and second products in products list:

    var searchCriteria = new List<Suitability>()
        {
            new Suitability() { Key="a", Value="b" },
            new Suitability() { Key="a", Value="c" }
        };
    
    var products = new List<Product>()
        {
            new Product()
                {
                    Items = new List<Suitability>() {
                                new Suitability() { Key="a", Value="b" },
                                new Suitability() { Key="a", Value="c" }}
                },
            new Product()
                {
                    Items = new List<Suitability>() {
                                new Suitability() { Key="a", Value="b" },
                                new Suitability() { Key="a", Value="c" },
                                new Suitability() { Key="b", Value="c" }}
                },
            new Product()
                {
                    Items = new List<Suitability>() {
                                new Suitability() { Key="c", Value="d" }}
                }
        };
    
        var predicate = PredicateBuilder.True<Product>();
    
        foreach (Suitability criteria in searchCriteria)
        {
            string tempKey = criteria.Key;
            string tempValue = criteria.Value;
            predicate = predicate.And(p => p.Items.Any(
                             s => s.Key == tempKey && s.Value == tempValue));
        }
    
        IEnumerable<Product> productsResult = products.Where(predicate.Compile());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just took a look at this answer , and I noticed the following
I know this question has been asked before, and I took a look at
This took me a while to figure out and I found the answer on
Hello and thanks in advance for taking a look at this. I have discovered
This is a question out of curiousity. Today I took a look at the
I just took a look at jqgrid . Has anyone tried implementing this plugin,
A took a look at http://erlang.org/doc/apps/inets/http_client.html and found the following: An ordinary asynchronous request.
Took me a while to find an answer for this so thought I'd share
I took a look at some questions here at stack overflow like this &
So I took a look at the x86 assembly language; All the commands are

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.