怪物奇妙物语

宇宙无敌超级美少男的怪物奇妙物语

首页 新随笔 联系 管理
  819 随笔 :: 0 文章 :: 2 评论 :: 16万 阅读

如何通过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

posted on   超级无敌美少男战士  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
历史上的今天:
2022-08-21 grid 布局 css
点击右上角即可分享
微信分享提示