I\'m trying to implement search functionality in an ASP.NET MVC 2 application. I create an expression based on criteria entered by the user:
public ViewResul
What about dynamically create your query? Like this:
var customers = CustomerRepository.AllEntities();
if (!forename.IsNullOrEmpty())
customers = customers.Where(p => p.Forename == forename);
if (!familyname.IsNullOrEmpty())
customers = customers.Where(p => p.FamilyNames.Any(n => n.Name==familyname));
if (dob.HasValue)
customers = customers.Where(p => p.DOB == dob);
I don't know if this works but I think this could be more efficient.