I know it has been a couple months since I first wrote part 1 of building a repository pattern with an EF model, but here we are. I am finally getting around to writing part 2. If you remember, in part 1 I talked about creating an EF model (EDMX) connected to an existing SQL server database and mapping the stored procedures to the entities and creating the generic repository classes. This post will dive into how to create the concrete implementation to the repository that will be used by a WCF service.

Using the example of a Customer entity, we need to create the customer repository interface and class:

After implementing this class, we will have a CustomerRepository object that we can use to Select, Insert, Update, and Delete Customer objects from the DbContext. I created a separate interface and class for each entity. Since I am using the repository from a WCF service I wanted a way to group my repositories and easily call the Select and Update methods from the service. I did some research on the Unit of Work pattern and I decide on implementing a variation like so: