.NET Core Tutorials – Razor Pages – Adding a model


You can download the project code here

 

With this step of the tutorial, you can add classes to manage the data in the database.

We will use Entity Framework Core as data ORM to work with the database.

The classes used as model are know as POCO because they don’t have any dependency with EF Core and define the properties of the data that are stored in the database.

  1.  Right-click project > Add > New Folder08.png
    Name the folder “Models”
    Right click “Models” folder
    Select Add > Class
    09.png
    Name the class Movie
    10
  2. Copy this code inside Movie.cs:using System;
    using System.ComponentModel.DataAnnotations;namespace MoviesManager.Models
    {
    public class Movie
    {
    public int ID { get; set; }
    public string Title { get; set; }[DataType(DataType.Date)]
    public DateTime ReleaseDate { get; set; }
    public string Genre { get; set; }
    public decimal Price { get; set; }
    }
    }The “Movie” class contains:

    “ID”: field required as primary key.

    [DataType(DataType.Date)]: The DataType attribute specifies the type of the data (Date).
    With this attribute is not required to enter time in the date field. Only the date is displayed (not time).

  3. Build the project to check no compilation errors.

 

You can download the project code here

 

GOTO next step “.NET Core Tutorials – Razor Pages – Scaffold the movie model”

GOTO topic index

This content is property of Matias Creimerman.
Any misuse of this material will be punishable.
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

About the author:

Matías Creimerman
Matías Creimerman

Profesional Website

Linkedin

Blog

Medium

Youracclaim Badges

Microsoft Tech Profile

Aboutme

Connection

Portfoliobox

Github

ASP.NET Forum

Facebook

Twitter

Youtube

Crunchbase

Matías Creimerman Certifications

Matias Creimerman

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s