generate models from a database in an ASP.NET MVC application edit button Edit

Murugan Andezuthu Dharmaratnam | calendar 30 March 2024 | 173

To generate all models from a database in an ASP.NET MVC application, you can use the Entity Framework's reverse engineering feature known as Scaffold-DbContext. This command creates entity classes and a DbContext class based on the schema of the existing database. Here's how you can do it:

Install the required NuGet packages:

Microsoft.EntityFrameworkCore.Tools and

Open the Package Manager Console: In Visual Studio, go to Tools ? NuGet Package Manager ? Package Manager Console. Run the Scaffold-DbContext command

Scaffold-DbContext "ConnectionString" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models