To make the application portable and easy to test, you'll use an in-memory database with Entity Framework Core. Nate explains how to set up the provider and plug it in to your project.
- [Instructor] All of the data about the hotel's rooms and bookings will be stored in a database. We'll use Entity Framework to connect our API to a database provider. Entity Framework Core is the latest version, and we can use a new feature of EF Core to set up an in-memory database provider. I need to install some packages, which I can do from the NuGet package manager. I'm going to look for microsoft.enityframeworkcore, and I can install the base Entity Framework Core package.
And I can also install the InMemory package. The beauty of using an InMemory database for development is that we can simply swap it out for a real database when we go to production. Next, we need to add a DbContext class. We can just add this straight to the root of the project. Add a class called HotelAPIContext. This will inherit from the DbContext base class, which we need to import from Entity Framework Core.
We need to add a constructor that takes a DbContextOptions class called options, and then simply pass it down to the base constructor. Here we can also add all of the Db sets, or tables if you will, that will be tracked on the context. We'll add one Db set for a type of object called RoomEntity, which we'll create in a moment. We'll call this Db set Rooms. Over in the Startup class, we need to add a using at the top, using Microsoft.EntityFrameworkCore, if this is not here some of the autocomplete doesn't work.
And scroll down to ConfigureServices. Somewhere in ConfigureServices, I'm going to say use an in-memory database, and definitely want to make sure make a note that we want to swap this out in production. We can say services.AddDbContext, giving it the HotelAPIContext type, and then for the options, you can say options.UseInMemoryDatabase.
That will enable the InMemory feature of EF Core. That takes care of wiring up the InMemory database provider. Next, we'll create the model classes that will be used for the database context.
- REST vs. RPC
- Using HTTP methods (aka verbs)
- Returning JSON
- Creating a new API project
- Building a root controller
- Routing to controllers with templates
- Requiring HTTPS for security
- Creating resources and data models
- Returning data and resources from a controller
- Representing links (HREFs)
- Representing collections
- Sorting and searching collections
- Creating forms
- Caching and compression
- Authentication and authorization for RESTful APIs
Skill Level Intermediate
Building Web APIs with ASP.NET Core (2016)with Chris Woodruff1h 7m Intermediate
Deploying ASP.NET Core Applicationswith Nate Barbettini57m 57s Intermediate
1. REST API Concepts
2. Building a Basic API
3. Securing the API
4. Representing Resources
5. Representing Links
6. Representing Collections
7. Sorting Collections
8. Searching Collections
9. Forms and Modifying Data
10. Caching and Compression
11. Authentication and Authorization
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.