MySql Scaffolding an Existing Database in EF Core
官方文档详见:https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core-scaffold-example.html
Scaffolding a Database Using Package Manager Console in Visual Studio
Open Visual Studio and create a new Console App (.NET Core) for C#.
Add the MySQL NuGet package for EF Core using the Package Manager Console. For example, use the following command to add the
MySql.Data.EntityFrameworkCore v8.0.13
package:Install-Package MySql.Data.EntityFrameworkCore -Version 8.0.13
NoteThe version (for example,
-v 8.0.13
) must match the actual Connector/NET version you are using. For current version information, seeTable 9.2, “Supported versions of Entity Framework Core”.Install the following NuGet packages by selecting either Package Manager Console or Manage NuGet Packages for Solution from the Tools and then NuGet Package Manager menu:
Microsoft.EntityFrameworkCore.Design
EF Core 1.1 only: Also add the
MySql.Data.EntityFrameworkCore.Design
package.Microsoft.EntityFrameworkCore.Tools version 1.1.6
(for EF Core 1.1) andMicrosoft.EntityFrameworkCore.Tools version 2.0.3
(for EF Core 2.0)NoteThe .NET tools are included in the .NET Core 2.1 SDK and not required or supported for EF Core 2.1. If this is an upgrade, remove the reference to that package from the .
csproj
file (version 2.0.3 in this example) :<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
Open Package Manager Console and enter the following command at the prompt to create the entities and DbContext for the
sakila
database (adjust the connection-string values to match your settings for theuser=
andpassword=
options):Scaffold-DbContext "server=localhost;port=3306;user=root;password=mypass;database=sakila" MySql.Data.EntityFrameworkCore -OutputDir sakila -f
Visual Studio creates a new
sakila
folder inside the project, which contains all the tables mapped to entities and thesakilaContext.cs
file.
最新文章
- Linux服务器jps报process information unavailable
- Golang 逐行读写之scanner.Scan
- java中参数传递方式
- hdu 3804 树链剖分
- thymeleaf 模板引擎
- Android studio 开发中 用git实现批量忽略特定文件的方法
- 豆瓣api之OAuth认证
- ACboy needs your help again!
- 安装sysbench遇到找不到库文件的问题
- 责任链模式(Chain of Responsibility)
- Android中关于JNI 的学习(三)在JNI层訪问Java端对象
- 探寻 webpack 插件机制
- mybatis bug之org.apache.ibatis.exceptions.PersistenceException:
- vue+axios跨域解决方法
- vue-cli 引入阿里巴巴字体图标:注意点
- java 基本理论知识点
- gitlab相关
- 第十九章 springboot + hystrix(1)
- Spring +quartz获取ApplicationContext上下文
- Mysql储存过程2:变量定义与参数传递