I'm thinking which way to go and can't decide which one is better. Maybe you can give me the killer idea :)
My problem: I have a generic repository built on top of NHibernate. It's interface is very simple, such as Get(object id), Save, Delete etc. Sometime this interface works fine, but sometime it doesn't. For example, several entities in my project has a property named Code (but not all). I want to be able to get an entity not only by primary key, but also with this property. Another situation is when I need to filter some entities with dates, or provide other filtering criteria which are specific to individual entities. Currently I'm thinking of the following solutions:
- Linq - I can return an IQueryable object from Repository for each type, then filter the query using linq expressions. I don't like this idea, because if I go this way, I don't see the reason behind Repository.
- Entity specific repository - Here I can build an entity specific on top of the generic repository. It will have methods such as Get(DateTime dateFrom, DateTime dateTo) etc. The drawback is that I'll have to create a repository class for each entity object. The good side is that it will be much easyer to persist/delete an object graph from database, because it knows entity's dependencies.
- You tell me please :)