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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:38:13+00:00 2026-06-10T09:38:13+00:00

I will preface this with I’m actively searching for the solution to this problem

  • 0

I will preface this with I’m actively searching for the solution to this problem but figured I might short cut some research and development time if someone here on stack has already figured this out. (I have found nothing online so here goes)

We have a case in an application framework we are building where we need the capability to take in a set of Predicates (List<Expression<Func<T,bool>>>) and parse it in a search framework.

Right now we have the capability to filter in this way being that:

//Assume predicates is passed as a method argument.
//     of List<Expression<Func<T,bool>>>
//Assume user is passed in as a method argument.
//Assume FilterToUserAccess is a custom extension method that restricts the dataset
//    to access restrictions.
var query = _dbContext.Set<EntityType>()
     .FilterToUserAccess(user);
foreach(var p in predicates){
     query = query.Where(p);
}

return p.ToList();

The reason we need to do this is for scale-ability of filterable objects. However for a quick search this is not possible given the built in capabilities of EF. What I need to be able to do is:

Object A (lets pretend it’s a race car) and we want to search make, model, team, and driver in a quick search box. So if I enter “Earnhardt”, it would search all race car entity properties being make, model, team, and driver. I would end up with all the DEI cars as well as Dale Jr. I would like to use the same approach so we can configure a searchable entity and reflect the search configuration on application start. I would ideally like to make some way of having the query look similar to this:

//Assume predicates is passed as a method argument.
//     of List<Expression<Func<T,bool>>>
//Assume user is passed in as a method argument.
//Assume FilterToUserAccess is a custom extension method that restricts the dataset
//    to access restrictions.
var query = _dbContext.Set<EntityType>()
    .FilterToUserAccess(user);
foreach(var p in predicates){
    query = query.Or(p);
}

return p.ToList();

I realize I can do:

_dbContext.Set<EntityType>().Where(predicate1 || predicate2 || predicate3)

However this will not work for the approach we want to take to solve this problem. Ideally an admin for one of our client sites would be able to go in and configure an additional search term with a single click to be included in any and all quick searches for that entity type like we can currently pull off with Filters which use the standard .Where(...) “and” chaining logic.

  • 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-10T09:38:14+00:00Added an answer on June 10, 2026 at 9:38 am

    First solution was a bust, however with some more digging there is an incredibly simple solution, verified and works.

    Step 1: install the NuGet package for LinqKit.

    Step 2: Enjoy the code below

    using (ISampleRepository repo = new SampleRepository())
    {
        var predicates = new List<Expression<Func<Customer,bool>>>(){
            (x => x.FirstName.Contains(searchValue)),
            (x => x.LastName.Contains(searchValue))
        };
    
        var lambda = PredicateBuilder.False<Customer>();
        lambda = predicates.Aggregate(lambda, (current, p) => current.Or(p).Expand());
    
        var query = repo.QueryCustomers().AsExpandable().Include(x => x.Phones).Where(lambda);
        return query.Take(500)
            .ToList()
            .Select(x => x.ToDTO())
            .ToList();
    }
    

    This is just the spike sample but doing the same thing with a method taking in ->

    List<T> QuickSearch<T>(string input) ...
    

    Will be able to use the same approach. You have a collection of predicates still in Expression form passed in, then you use the predicate builder tricks to pull the query off. Then using the AsExpandable() allows you to execute the combined predicate created using the predicate builder.

    Hopefully this is helpful to more than just me, but this is the solution I’m going with as it’s quite a bit less code. Allows you to build your predicates elsewhere… and still combine them in an “OR” statement after the fact.

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

Sidebar

Related Questions

I will preface this by I am new to XNA and I realize what
I will preface this question with the disclaimer that I know there are many
Let me preface this by saying I am extremely new to git but have
I will preface this question by saying, I do not think it is solvable.
To preface, I've seen the command to answer this question before, but now I
I will preface this question with the fact that I am extremely new to
Let me preface this problem with the following: I've only tested this using the
As a preface, I really do not want the exact solution to my problem,
This is a C# winforms app. Preface: I am creating a form that will
To preface this, I know there are discussions on this in various places. Half

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.