views:

173

answers:

2

The number of query conditions is determined by user selections at runtime, ie

var results= from r in db.Table 
             where condition A && condition B && ... condition XX...

Is the best way to handle this to build a string variable and append to it or is there another way?

+3  A: 

Try using the extension methods. You can use these to customize your query based on values of variables. Otherwise, you can look at Dynamic Linq in the VS2008 samples.

 var query = db.Table;
 if (lookForX)
 {
     query = query.Where( t => t.fieldX == X  );
 }
 if (lookForY)
     query = query.Where( t => t.fieldY == Y );
 }
tvanfosson
+1  A: 

See this question and my answer about dynamic queries

Geoff