Start a new Web Application Project (Either ASP.NET Core 2 or 3). Name the project RazorFilms. This will form part of the namespace that will need to be referenced in the class files of the application.
The application will make use of a Database and the management of the database will be done via Entity Framework. Therefore we need to ensure additional packages are installed.
Package Requirements
Managed through:
Note: Tools needed for migration.
Create a Model by adding a model folder and then a class file ie Film.cs
Tip: The [Key] attribute tells the Model the Id is a primary key. The [Required] attribute tells the Model that the FilmTitle is a required field. Validation on this can then be done server and/or client side.
Set up Connection String in appsettings.json
Setting Up a Context, we'll save it as ApplicationDbContext.cs
Add Context to the Startup.cs
Dependency injection, via ConfigureServices method:
Use the console to run the migration command and then update the database
Add-Migration Initial
Update-Database
It is important to run both console commands. The Add-Migration command can be given a name by the developer. It this example, it was sensible to call it Initial.