Sunday, January 31, 2010

I've just been around the block with the Repository pattern and Linq, and here are my thoughts.

The Repository pattern is designed to hide all data access concerns behind a facade, so for clients of the repository, quite simply, there is no Linq. I've seen a lot of people try to have their cake and eat it too, where they put the repository pattern in place then try all manner of witchcraft to let the client use Linq through it. This is bad. This is ice-skating uphill. Don't do it.

If you have a small project and want to use Linq for business logic, don't use the Repository pattern. If you have a large project and want a testable facade, or a storage agnostic repository, use the pattern, but make sure you pass domain objects to it, not data access objects.