Reverse engineering the database
Reverse engineering can be performed on the NuGet Package Manager
console. We have already seen how to open it, so just execute the following command to scaffold the context and models files:
Scaffold-DbContext "Server
(localdb)\mssqllocaldb;Database=MasteringEFCoreDbFirst;
Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Note
Sometimes we might get errors stating that The package could not be located
. The workaround would be opening the project in a separate solution. If we get an Unable to open the database
error, then providing access in the SQL Management Studio (connecting the locals from the studio) would resolve the issue. SQL Server Management Studio (SSMS) is a free version and can be downloaded from https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms.
Please refer to the following screenshot:
The scaffolding process generates database context files and corresponding...