O'Reilly logo

Applied ASP.NET 4 in Context by Adam Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required