I use ASP.NET Web API and Repository pattern.
And I want to add where clause dynamically. Like,
//controller
static readonly ICustomerRepository repository = new CustomerRepository();
//
var result = repository.GetAll();
if (form['name'] != null) result.Where( p => p.custName.Contains( form['name'].toString() ) );
if (form['attribute1'] != null) result.Where( p => p.attribute1.Equals( form['attribute1'].toString() ) );
return result;
//
Isn’t there any afraid of IOs?
It’s not really clear what you mean, but the query will only be sent to the database when you try to execute it – which is presumably in some of the code which calls your method. It’s not like it’s going to execute once for
GetAll, then once for the firstWhereclause, then once for the secondWhereclause. It will all be packaged into a single query, when you start fetching the data from theIQueryable<>.