c#构建动态linq查询

c#构建动态linq查询,c#,linq,C#,Linq,我有一个列表a,它有一些属性 另一个列表B 它有一些特性 两个布尔值bool c和bool d 我想根据以下条件筛选列表A 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 你有没有试过这样的方法: a = // some context; if (b.Count > 0) a = a.Where(

我有一个
列表a
,它有一些属性

另一个
列表B
它有一些特性

两个布尔值
bool c
bool d

我想根据以下条件筛选列表A

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

你有没有试过这样的方法:

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 );

你有没有试过这样的方法:

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 );

你试过什么?您是否有一些代码,说明您到目前为止尝试了什么以及您在哪里遇到了问题?你有你在研究期间读过的链接列表吗?如何提出一个好问题:@ArunYogeshwaran你所说的单词
动态
是什么意思?你试过什么?您是否有一些代码,说明您到目前为止尝试了什么以及您在哪里遇到了问题?你有你在研究期间读过的链接列表吗?如何提出一个好问题:@ArunYogeshwaran你所说的单词
Dynamic
是什么意思?但是我不想在同一个列表上一次又一次地应用筛选器@vd如果你担心新请求会随着每个筛选器一次又一次地发送到db,我认为你不应该这样做。这样,您实际上只是准备查询,而不是查询数据库。以这种方式编译查询后,将使用命令
var data=a.ToList()发送请求f.e
@ArunBut我不想一次又一次地在同一个列表上应用筛选器@vd如果您担心新请求会随着每个筛选器一次又一次地发送到db,那么我认为您不应该这样做。这样,您实际上只是准备查询,而不是查询数据库。以这种方式编译查询后,将使用命令
var data=a.ToList()发送请求f.e@Arun