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.
Create data model classes - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
Create data model classes
- [Instructor] One great thing about Entity Framework is that you can use simple classes to represent database entities. These are sometimes called POCOs, or plain old CLR objects. Let's create a model that will represent a room stored in the database. I'll do this in the models folder and create a class called room entity. This entity will have three properties. We'll give it a Guid ID. We'll give it a string name. And also, we'll give it an int rate. I'm storing the rate as an int here because storing decimals with the correct precision can be a little tricky. Instead of dealing with that, I'll just cheat and store the prices as cents, as long as I remember to divide by 100 later. Next, let's create the resource that the API will actually return to the client. This will also go in the models folder, and I'll call this simply room. This one will inherit from resource. And we'll add only two properties here. A string name. And a decimal rate. You'll notice that this room resource…
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
-
-
-
-
-
-
-
-
-