0
是否有可能做一個包含if
的查詢?我想要做的是根據同一個表中另一列的值選擇兩個特定的列。linq查詢使用if
所以如果column1
值0
,我想選擇custom1
和custom2
,如果它是1
,我想選擇custom3
和custom4
。
是否有可能做一個包含if
的查詢?我想要做的是根據同一個表中另一列的值選擇兩個特定的列。linq查詢使用if
所以如果column1
值0
,我想選擇custom1
和custom2
,如果它是1
,我想選擇custom3
和custom4
。
var q = from c from MyTable
select new
{
item1 = (c.column1 == 0) ? custom1 : custom3,
item2 = (c.column1 == 0) ? custom2 : custom4
}
的可能重複【如何做如果LINQ查詢語句(http://stackoverflow.com/questions/1153486/how-to-do-if-statement-in-linq-query) – 2010-08-30 19:49:21
那一個看起來很複雜,但我想你是對的。我在「尋找」的答案是可以在linq中做條件運算符。 – peirix 2010-08-31 05:58:26