I have a problem with PredicateBuilder Class.
I have a 3 class like.
public class A
{
public int val1 {get;set;}
public int val2 {get;set;}
public List<B> listb {get;set;}
}
public class B
{
public int val3 {get;set;}
public int val4 {get;set;}
public List<C> listc {get;set;}
}
how can i search val3 in B class I need a search like :
var query = PredicateBuilder.True<A>();
query = query.And(x => x.listb.Where(b=> b.val3 == 1);
Simply replace .Where()
with .Any()
to create a true/false boolean condition:
query.And(x => x.listb.Any(b => b.val3 == 1));
This will return all A
records where any item in listb
contains a val3
of 1
. If you only want A
records where all items in listb
match the condition, use .All()
:
query.And(x => x.listb.All(b => b.val3 == 1));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.