8. Add a Model
Create a Model File
Step 1: Add a file named Movie.cs
to the Models folder.
Update the Models/Movie.cs
file with the following code:
using System.ComponentModel.DataAnnotations;
namespace MvcMovie.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 an Id
field, which is required by the database for the primary key.
The DataType attribute on ReleaseDate
specifies the type of the data (Date
). With this attribute:
The user isn't required to enter time information in the date field.
Only the date is displayed, not time information.
Install Model Design Softwares
Step 2:
dotnet tool install --global dotnet-aspnet-codegenerator
Step 3:
dotnet tool install --global dotnet-ef
Step 4:
dotnet add package Microsoft.EntityFrameworkCore.Design
Step 5:
dotnet add package Microsoft.EntityFrameworkCore.SQLite
Step 6:
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
Step 7:
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
Last updated