2009-09-24 90 views
0
IQueryable<SomeType> result = (from x in Context.XXX select x); 

现在我需要做的是以下(写伪代码,我需要实际的代码):如何写一个LINQ查询为此

foreach(var i in items) 
{ 
    // Where the object "i" has 2 properties 
    // 1) i.Operator (values of which can be AND or OR) 
    // 2) i.SomeID (values of which can be 1 .. 10) 

    // I need to build the LINQ query with "ands" and "ors" based on the i's in this foreach 
} 
+1

你怎么知道每个AND和OR的范围是什么?你只是想链接它们(这可能是错误的逻辑) – 2009-09-24 12:53:18

回答

1

天真的方法是链通话到Where方法,但这样你只能实现AND行为

查看由Joseph Albahari提供的PredicateBuilder类。它允许建立与OR运算符