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

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

主站蜘蛛池模板: 屯昌县| 花莲市| 潮安县| 安西县| 墨脱县| 新泰市| 白沙| 东阿县| 清河县| 慈利县| 轮台县| 青川县| 阿鲁科尔沁旗| 黄山市| 秀山| 吉安市| 昌乐县| 土默特右旗| 玛沁县| 高密市| 邵阳市| 北海市| 二连浩特市| 潼南县| 大埔区| 天镇县| 赤峰市| 宿松县| 金山区| 远安县| 兴义市| 杭州市| 遂昌县| 齐齐哈尔市| 三亚市| 平江县| 慈溪市| 晋州市| 屏东县| 阆中市| 沂水县|