I’ve been a huge fan of the repository pattern mainly because it allows a well known and standardized “façade” to any data access implementation, its like another layer of abstraction for your data access strategy.
Martin Fowler has very simple (too simple) explanation of the repository pattern here, and here is another example about the repository pattern, and you still don’t get it maybe you want to know: What purpose does the Repository Pattern have?
But I am here to tell you about another pattern, the Composite Specification Pattern and how is it used to query a repository.
The Composite Specification pattern is pretty cool and clever and explained in this links:
In those 2 links the guys at LosTechies.com have created a generic repository for you to use including the speciation pattern used to query the repository. Which can be very useful if you are dealing with in memory repositories, in memory filtering, searching etc, but if you have actual database you need to take it a step further and learn how to translate the specifications into something that your data access strategy, but that’s the beauty of the pattern it abstract that to a higher lever so the access strategy can vary and evolve independently of consumer user the repository.
I think next step is to take this repository pattern along with the composite specification and make an asynchronous repository pattern, I have a few ideas in mind, which I might post about in the near future.