Creating the Repository
The first step to creating a repository is to create a class that drives the Entity Framework to connect to our database and use our model types to represent records. There are lots of different ways to do this, but I like to use a separate class that I think of as an adapter between the repository class and the Entity Framework.
Creating the Entity Framework Adapter
Create a new class in the Models/Domain/Repository
folder called EFAdapter
and set its contents to match Listing 24-1.
Listing 24-1. The EFAdapter class
class EFAdapter : DbContext {
public EFAdapter(string connectionName)
: base(connectionName) {
// do nothing
}
public DbSet<Competition> Competitions { get; set; } public ...
Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.