InterviewSolution
| 1. |
How To Scaffold Model From Existing Database In Asp.net Mvc Core? |
|
Answer» To scaffold MODELS from existing database in ASP.NET MVC CORE, GO to Tools –> NuGet Package Manager –> Package Manager Console Now execute following command: Scaffold-DbContext "Server=datbase-PC;Database=TrainingDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models If you get an error "The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet" , SIMPLY Close the Visual Studio and open again. This creates .cs files related with all database tables into Models folder of your project. This also creates a database context (in this case the name will be TrainingDatabaseContext.cs as the database name is TrainingDatabase). To scaffold models from existing database in ASP.NET MVC Core, go to Tools –> NuGet Package Manager –> Package Manager Console Now execute following command: Scaffold-DbContext "Server=datbase-PC;Database=TrainingDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models If you get an error "The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet" , simply Close the Visual Studio and open again. This creates .cs files related with all database tables into Models folder of your project. This also creates a database context (in this case the name will be TrainingDatabaseContext.cs as the database name is TrainingDatabase). |
|