如何通过efcore生成实体模型
To create an Entity Data Model from the database using the Database First approach in EF Core, we’ll follow these steps:
- Create a new console application project
- Create a Model using the Scaffold-DbContext Command
Creating a new console application project
In this example, we’ll use Visual Studio 2019. If you don’t have a copy of Visual Studio 2019 installed in your system, you can download a copy from here: https://visualstudio.microsoft.com/downloads/
If Visual Studio 2019 has been successfully installed in your system, follow the steps outlined below to create a new console application project in Visual Studio.
- Open Visual Studio 2019
- On the File menu, click on New > Project
- In the "Create a new project" dialog, select "Console App (.NET Core)"
- Click Next
- Now specify the name and location of the project
- Click Create as shown in Figure 1
This would create a new console application project in Visual Studio 2019. We'll use this project in the subsequent sections.
Installing the necessary packages
Now that the database has been restored, specify the following commands at the NuGet Package Manager console to install the necessary packages.
Install-Package Microsoft.EntityFrameworkCore Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Microsoft.EntityFrameworkCore.SqlServer
Create a Model from the database
So far so good. To create the Entity Data Model, we'll take advantage of the Scaffold-DbContext command. Here's how the syntax of this command looks like:
Scaffold-DbContext [-Connection] [-Provider] [-OutputDir] [-Context] [-Schemas>] [-Tables>] [-DataAnnotations] [-Force] [-Project] [-StartupProject] [<CommonParameters>]
To create the Entity Data Model for our AdventureWorks database, specify the following command at the Package Manager Console.
Scaffold-DbContext "Server=JOYDIP;Database=AdventureWorks2017;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
参文地址 www.mssqltips.com
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2022-08-21 grid 布局 css