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 - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Create a resource class2m 19s
-
(Locked)
Load data from configuration1m 35s
-
(Locked)
Return data from a controller3m 5s
-
(Locked)
Set up an in-memory database2m 22s
-
(Locked)
Create data model classes1m 44s
-
(Locked)
Seed the database with test data5m
-
(Locked)
Return a resource from a controller4m 47s
-
(Locked)
Move data access to a service4m 39s
-
(Locked)
Map models automatically3m 47s
-
-
-
-
-
-
-
-
-