PredicateBuilder and Multi-Level Nested Entities

I am trying to wrap my head with dynamic nested predicate expressions. This is not good.

Basically, I need to be able to create dynamic queries on a fixed set of properties, but on a dynamic (and potentially unlimited) number of (nested) levels.

Taking family tree as an example, I should be able to write queries to get any of these results:

  • find all the parents who have children.
  • find all parents who have children whose name starts with "k"
  • find all parents who have children, who have children born after 01/01/2012 who have children named "John".
  • and etc.

I can write something like this manually which works great.

var pred = PredicateBuilder.True<db.Entity>();
pred = pred.And(n => 
    n.Children.Where(
        m => m.Children.Where(
            o => o.Name.Contains("John")
        ).Any()
    ).Any()
);

      

Question: How can I generate the above code dynamically with mixed properties and operators on any number of nested levels?

+3
c # asp.net linq entity-framework predicatebuilder


source to share


No one has answered this question yet

Check out similar questions:

509
Failed to update EntitySet - because it contains DefiningQuery element and no <UpdateFunction>
7
Difference between PredicateBuilder <True> and PredicateBuilder <False>?
five
Create a nested list of items from parent referenced objects
2
OR nesting using Linq PredicateBuilder
2
How to work with EF generating a SQL statement nested too deep
2
ASP.NET Core PredicateBuilder with multiple categories and subcategories
1
PredicateBuilder returns all predicate.Or users
0
Double filter though nested ListView asp.net
0
binbin ling predicatebuilder tries to add AND (field1 = string1 or field1 = string2) to the end of the predicate
0
Linq request to return parent or last child



All Articles
Loading...
X
Show
Funny
Dev
Pics