I have a standard repository interface in C# which includes the following methods:
IEnumerable<T> GetAll();
T GetById(int id);
void Delete(T entity);
void Add(T entity);
At my domain layer all I am instantiating is a new Unit of Work wrapper and passing it to a repository. The Unit of Work wrapper class hides whether I'm using NHibernate or Entity Framework and exposes a Commit() method.
In my domain layer, how can I query for objects which meet only a particular criteria?
I think what I'm doing at the moment is terribly inefficient. I am currently doing this:
var results = myRepository.GetAll().Where......
If I have a very large amount of objects, is GetAll() going to return every one of them before filtering out the ones I don't need? How can I prevent unwanted object from being returned at all?
Obviously I could add more methods to the interface, but this doesn't seem in keeping with exposing only CRUD operations via the interface.
i.e. - I don't think I should be adding things like (but maybe I'm wrong):
IList<T> GetAllWhereMeetsMyCriteria();