score:5

Accepted answer

it is also possible to add an inline if in the where clause

lstitem.itemssource = 
     (from item in items
      where (test == "s" ? item.property1 == "somevalue" : item.property2 == "someothervalue")
      select item);

score:2

well, you could start by boiling the expression down to:

func<items, bool> expr;

if(type== "s")  
{ 
    expr = (item => item.property1 == "somevalue");
}
else
{
    expr = (item => item.property2 == "someothervalue");
}

var items = items.where(expr);

of course, the game plan is really to make it all a single statemnet, but this makes it a little more manageable i think :)

jim

score:3

i like:

lstitem.itemssource = items.where(type == "s" ? 
                 item => item.property1 == "somevalue":
                 item => item.property2 == "someothervalue");

score:4

you can chain your commands within if statements. e.g.:

var items = from item in items 
            select item; 

if(type== "s")  
{     
   items = items.where(item => item.property1 == "somevalue");
}  
else  
{  
   items = items.where(item => item.property2 == "someothervalue");
}  

or even just write the tidier lambda structure in you orignal code:

if(type== "s") 
{    
    lstitem.itemssource = items.where(item => item.property1 == "somevalue");
} 
else 
{ 
    lstitem.itemssource = items.where(item.property2 == "someothervalue");
}

Related Query

More Query from same tag