2009-09-24 100 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運算符