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

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).

主站蜘蛛池模板: 中西区| 阿尔山市| 东明县| 关岭| 盖州市| 易门县| 左贡县| 射洪县| 上蔡县| 调兵山市| 曲靖市| 华池县| 雷山县| 灵川县| 崇文区| 高密市| 五寨县| 永兴县| 申扎县| 利津县| 山丹县| 上高县| 金塔县| 娄烦县| 塔河县| 永州市| 临高县| 务川| 阿瓦提县| 哈巴河县| 新余市| 宜君县| 巴马| 海伦市| 蓬莱市| 洪泽县| 朝阳市| 于田县| 嘉禾县| 湖北省| 华蓥市|