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

Create data model classes - ASP.NET Core Tutorial

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

Start my 1-month free trial

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…

Contents