开发者

linq queries using if

Is it possible to do a query that contains an if? What I'd like to do is to select two certain columns based on the value of another column in the same table.

So if the value of column1 is 0, I'd like to select custom开发者_JS百科1 and custom2, if it's 1, I'd like to select custom3 and custom4.


var q = from c from MyTable
        select new
        {
            item1 = (c.column1 == 0) ? custom1 : custom3,
            item2 = (c.column1 == 0) ? custom2 : custom4
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜