tags:

views:

27

answers:

1

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 custom1 and custom2, if it's 1, I'd like to select custom3 and custom4.

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