From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

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

Set up an in-memory database

Set up an in-memory database - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Set up an in-memory database

- [Instructor] All of the data about the hotel's rooms and bookings will be stored in the database. We'll use Entity Framework core to connect our API to a database provider. While we're building the API, we can use the in-memory provider feature of EF core to quickly set up a test database. The beauty of using an in-memory database for development is that we can simply swap it out for a real database once we go to production. The first thing we need to do is add a DbContext. We'll do that at the root of the project. I'll add a new class and I'll call this HotelAPIDbConext. This DbContext needs to inherit from the DbContext base class. And I need to import that namespace from EF Core. There's a couple of lines of code I need to add which are mostly boilerplate code. I need to add a constructor, HotelApiDbContext. That accepts a DbContextOptions, just call this options. And all I need to do is just pass this down to the base method. Now, I'll declare the different Db sets, or tables if…

Contents