From the course: Learning Entity Framework Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create the DbContext

Create the DbContext - Entity Framework Tutorial

From the course: Learning Entity Framework Core

Start my 1-month free trial

Create the DbContext

- [Instructor] To use Entity Framework, we need to create a class that derives from DbContext base class. Each DbContext class that we write, will give us access to a specific database. The connection string can always be modified to point to different databases that can be used. The DbContext maps to a specific database that has a schema, that the DbContext understands. On that DbContext, you can create properties that are type of DbSet, of T. The generic type paramater T, will be an entity, like Actor is an entity in this demo console application. So if I want an Actor database, I'll simply create an Actor DbContext class, and implement a DbSet of Actor, on that class. In the Actor DbContext, DbSets, will map to tables in the database, like a table of actors. The mapping can become quite complex, but we won't be doing anything sophisticated at this point. So let's go ahead and see this in action. In our application, I need a class that derives from DbContext, so I'm going to go…

Contents