score:2

Accepted answer

you need to make use of predicatebuilder, if i am getting correctly you are making single query and you need conditions in it

iqueryable<product> searchproducts (params string[] keywords)
{
  var predicate = predicatebuilder.false<product>();

  foreach (string keyword in keywords)
  {
    string temp = keyword;
    predicate = predicate.or (p => p.description.contains (temp));
  }
  return datacontext.products.where (predicate);
}

dynamically composing expression predicates

score:0

you could use the system.linq.dynamic package available on nuget. you can also follow this guide on how to use the package.

in your case, i believe the query could be:

var query = iqueryable<datatype>();
foreach(string parameter in searchparameters)
{
   query = query.where("fieldname ==" + parameter );
}

// call the linq query at the end when all the conditions are built
var results = query.select(q => q.field).tolist();

this may work for your case, otherwise you could use a predicate builder as per pranay's suggestion.


Related Query

More Query from same tag