I often see example repository patterns that look like this:
public interface IRepository<T>
{
T GetById(int id);
IEnumerable<T> GetAllByName(string name);
}
But how do you handle cases where you may need to do a complex search? I don’t think it would be a good idea to add many methods to the interface that would make it end up looking like:
IEnumerable<T> GetAllByFirstName(string name);
IEnumerable<T> GetAllByLastName(string name);
IEnumerable<T> GetAllByFirstAndLastName(string name);
IEnumerable<T> GetAllByAddress(string name);
...
...
...
Use the Predicate Builder to dynamically build the where condition
Then build the conditions
Create a class to pass the search criteria