Get Started

Dependancies

VS 2022

SQL Server

SSMS

VS Code

Razor WebApp VS MVC

MVC (This)

dotnet new mvc -o Mvc

Lightweight

Separate Folders- Models, View & Controller

Like-React

Razor WebApp

dotnet new webapp -o RazorPages

Extremely Lightweight

Single Folder- Pages

Like- HTML Page

Start with MVC CRUD App

1. Create a web app

dotnet new mvc -o MVCwebApp
code -r MVCwebApp

2. Create Model

dotnet new mvc -o MVCwebApp
Models/Movie.cs

3. Reinstall Features

dotnet tool uninstall --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-aspnet-codegenerator
dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef

4. Add NuGet packages

dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.SQLite
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

5. Scaffold movie pages

dotnet-aspnet-codegenerator controller -name MoviesController

-m Movie

-dc MvcMovieContext

--relativeFolderPath Controllers

--useDefaultLayout

--referenceScriptLibraries

-sqlite

6. SQLite & SQL Server Config

Program.cs

7. Initial migration

dotnet tool install --global dotnet-ef

8. Migration

dotnet ef migrations add InitialCreate
dotnet ef database update

9. Dependency injection

Program.cs