官方文档详见: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

  1. Open Visual Studio and create a new Console App (.NET Core) for C#.

  2. Add the MySQL NuGet package for EF Core using the Package Manager Console. For example, use the following command to add theMySql.Data.EntityFrameworkCore v8.0.13 package:

    Install-Package MySql.Data.EntityFrameworkCore -Version 8.0.13
    Note

    The 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”.

  3. 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) and Microsoft.EntityFrameworkCore.Tools version 2.0.3 (for EF Core 2.0)

      Note

      The .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" />
  4. 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 the user= and password= 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 the sakilaContext.cs file.

MySql Scaffolding an Existing Database in EF Core的更多相关文章

  1. SQLite EF Core Database Provider

    原文链接 This database provider allows Entity Framework Core to be used with SQLite. The provider is mai ...

  2. EF core 性能调优

    Entity Framework Core performance tuning – a worked example Last Updated: February 25, 2019 | Create ...

  3. EF Core Model更新迁移

    EF Core 迁移 感觉就是以前EF Code First的自动同步数据库功能 内容:在你新增.更新TableModel后,如何自动化的更新DB中的真实Table.以及对这些更改进行一个版本控制. ...

  4. Asp.net core 学习笔记 ( ef core )

    更新 : 2018-11-26 这里记入一下关于 foreignKey cascade action 默认情况下如果我们使用 data annotation required + foreginkey ...

  5. .net Core 基于EF Core 实现数据库上下文

    在做项目时,需要将某一些功能的实体建立在另一个数据库中,连接不同的数据库用以存储记录.通过查找资料,实现EF Core上下文. 下面是实现上下文后的解决方案的目录: 1.UpAndDownDbCont ...

  6. Asp.net Core 通过 Ef Core 访问、管理Mysql

    本文地址:http://www.cnblogs.com/likeli/p/5910524.html 环境 dotnet Core版本:1.0.0-preview2-003131 本文分为Window环 ...

  7. MySQL官方.NET Core驱动已出,支持EF Core

    千呼万唤始出来MySQL官方.NET Core驱动已出,支持EF Core. 昨天MySQL官方已经发布了.NET Core 驱动,目前还是预览版,不过功能已经可用. NuGet 地址:https:/ ...

  8. ASP.NET Core 开发-Entity Framework (EF) Core 1.0 Database First

    ASP.NET Core 开发-Entity Framework Core 1.0 Database First,ASP.NET Core 1.0 EF Core操作数据库. Entity Frame ...

  9. net Core 通过 Ef Core 访问、管理Mysql

    net Core 通过 Ef Core 访问.管理Mysql 本文地址:http://www.cnblogs.com/likeli/p/5910524.html 环境 dotnet Core版本:1. ...

随机推荐

  1. Probability和Likelihood的区别

    Bayes for Beginners: Probability and Likelihood 好好看,非常有用. 以前死活都不理解Probability和Likelihood的区别,为什么这两个东西 ...

  2. 20190315xlVBA_删除无用的区域

    '经常遇见天眼查表格文件特别大,原因是使用了整个表格,虽然无法解释为什么,但是经过验证以下代码是凑效的 Private Sub DeleteUselessRegion(ByVal sht As Wor ...

  3. C#集合类型大揭秘

    集合是.NET FCL(Framework Class Library)的重要组成部分,我们平常撸C#代码时免不了和集合打交道,FCL提供了丰富易用的集合类型,给我们撸码提供了极大的便利.正是因为这种 ...

  4. 7.2 GRASP原则二:信息专家 Information Expert

    2.GRASP原则二:信息专家 Information Expert  What is a general principle of assigning responsibility to obje ...

  5. xxx征集系统项目目标文档

    分组:每四人一组 主题:xxx征集系统 成果: 讨论结束后,每组提交一份课堂讨论记录(电子版发表到博客上,纸质版小组成员签名,下节课提交). 每人根据课堂讨论结果提交一份系统利益相关者描述案例.撰写项 ...

  6. YII实现restful,postman进行接口测试

    Yii2 restful API文档 一.配置模块: 1.Config/main.php: 2.创建模块目录: 3.Module.php: 二.路由配置: 三.控制器: 四.Models: 五.测试: ...

  7. 【lintcode17/18】Subset, SubsetII

    题目:给定一个含不同整数的集合,返回其所有的子集. 样例:如果 S = [1,2,3],有如下的解:[[3],[1],[2],[1,2,3],[1,3],[1,2],[2,3],[]] 思路:因为此题 ...

  8. Python3+getopt解析命令行参数

    一.说明 在学C语言的时候就知道可以通过argc获取命令行参数个数,可以通过argv获取具体参数.但自己写的程序获取到的参数一是没有键值形式二是写的参数不能乱序,和系统命令不太一样. 再往后点知道有g ...

  9. ES5和ES6那些你必须知道的事儿(一)

    ES5和ES6那些你必须知道的事儿 ES5新增的东西 一.数组方法 1.forEach     用途:遍历,循环 对于空数组不会执行回调函数 //用法 array.forEach( function( ...

  10. Win10系列:C#应用控件基础19

    ScrollViewer控件 ScrollViewer控件包含一个水平和一个竖直滚动条以及一个可滚动的内容显示区域,在显示区域内可以放置其他可见控件.ScrollViewer控件的水平和垂直滚动条两端 ...