简体   繁体   中英

c# Building dynamic linq queries

I have a List A which has some properties.

Another List B which has some properties.

Two booleans bool c and bool d .

I want to filter the List A based on some conditions like

a.type == b.type only if B.count > 0
and
a.IsSomeCondition only if c is true
and
a.IsSomeCondition only if d is true

have you tried something like this:

a = // some context;
if (b.Count > 0)
a = a.Where( //some filter );
if (c == true)
a = a.Where( //some filter );
if (d == true)
a = a.Where( //some filter );

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM