官术网_书友最值得收藏!

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

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 data models (in our case, three files in total).

主站蜘蛛池模板: 惠安县| 毕节市| 乐昌市| 峨眉山市| 龙南县| 文化| 将乐县| 巴东县| 富源县| 高淳县| 平度市| 吴川市| 应城市| 金川县| 长宁县| 大理市| 施甸县| 天等县| 宜良县| 资中县| 雷山县| 中江县| 旬邑县| 龙门县| 永康市| 左云县| 南阳市| 准格尔旗| 肇州县| 苗栗县| 玛多县| 平舆县| 永新县| 岳池县| 高碑店市| 九寨沟县| 东宁县| 徐州市| 雷波县| 南通市| 嘉兴市|