How to design a unit testable domain model with Entity Framework Code First
I got this question a couple times already so I’ll save keystrokes and post here.
I don’t like the Repository pattern too much either, especially since the advent of IQueryable and Linq, which make it more of a burden than anything else and hinders usage of cooler things on top of lambdas and expressions.
The new EF 4.1 Code First API, specifically DbContext, fits almost perfectly with this new way of doing domain modeling.
What I need from my domain “context” class is:
- Add/Save/”Delete”
- Expose IQueryable for the aggregate roots
- Allow to eagerly load relationships (a.k.a. Include or Fetch)