ASP.NET Boilerplate(简称ABP)是.Net平台下一个很流行的DDD框架,该框架已经为我们提供了大量的函数,非常方便与搭建企业应用。官方文档:http://www.aspnetboilerplate.com/Pages/Documents

ABP+EF+SQL Server是比较推荐的组合,由于使用的是EF,那么也就意味着我们可以采用其他的数据库,比如MySQL、MariaDB

操作步骤:

Download Starter Template 下载开始模板

Download the starter template with ASP.NET Core and Entity Framework Core to integrate MySQL. Multi-page template with ASP.NET Core 2.x + .NET Core Framework + Authentication will be explained in this document.

下载 ASP.NET Core 和  Entity Framework Core 的模板用于集成 MySQL。这里使用的是多页面模板 ASP.NET Core 2.x + .NET Core Framework

Getting Started 开始

There are two Entity Framework Core providers for MySQL that are mentioned in the Micrososft Docs. One of them is the Official MySQL EF Core Database Provider and the other is Pomelo EF Core Database Provider for MySQL.

NOTE: The official provider doesn’t support EF Core 2.0 just yet, so the Pomelo EF Core Database Provider will be used in this example, instead.

Related issue: https://github.com/aspnet/EntityFrameworkCore/issues/10065#issuecomment-336495475

微软文档里提到了两个MySQL的Entity Framework Core类库。一个是官方的MySql.Data.EntityFrameworkCore,另一个是Pomelo EF Core Database Provider for MySQL。

注:由于官方的目前还不支持EF Core 2.0 ,所以本例中使用的是 Pomelo EF Core Database Provider for MySQL 。相关问题的讨论:https://github.com/aspnet/EntityFrameworkCore/issues/10065#issuecomment-336495475

Install 安装

Install the Pomelo.EntityFrameworkCore.MySql NuGet package to the *.EntityFrameworkCore project.

为 *.EntityFrameworkCore 项目 安装 NuGet 包 : Pomelo.EntityFrameworkCore.MySql

Configuration 配置

Configure DbContext 配置 DbContext

Replace YourProjectNameDbContextConfigurer.cs with the following lines

使用如下代码 替换文件 YourProjectNameDbContextConfigurer.cs 内容

public static class MySqlDemoDbContextConfigurer

{

//CopyRight codebye.com

public static void Configure(DbContextOptionsBuilder builder, string connectionString)

{

builder.UseMySql(connectionString);

}

//CopyRight codebye.com

public static void Configure(DbContextOptionsBuilder builder, DbConnection connection)

{

builder.UseMySql(connection);

}

}

Some configuration and workarounds are needed to use MySQL with ASP.NET Core and Entity Framework Core.

一些配置和工作环境 需要使用 MySQL

Configure connection string 配置连接字符串

Change the connection string to your MySQL connection in *.Web.Mvc/appsettings.json. Example:

修改 *.Web.Mvc/appsettings.json 文件中的连接字符串,使用MySQL连接字符串。例如:

{

"ConnectionStrings": {

"Default": "server=codebye.com;uid=root;pwd=codebye.com;database=codebyedb"

},

CopyRight codebye.com ...

}

A workaround

To prevent EF Core from calling Program.BuildWebHost() rename BuildWebHost. For example, change it to InitWebHost. To understand why it needs to be renamed, check the following issues:

为了阻止 EF Core 调用 Program.BuildWebHost() ,需要重命名 BuildWebHost 。例如,改为 InitWebHost 。关于为何需要重命名,可以查看下面的问题讨论:

Create Database 创建数据库

Remove all migration classes under *.EntityFrameworkCore/Migrations folder. Because Pomelo.EntityFrameworkCore.MySql will add some of its own configurations to work with Entity Framework Core.

Now it’s ready to build the database.

Select *.Web.Mvc as the startup project.

Open Package Manager Console and select the *.EntityFrameworkCore project.

Run the add-migration Initial_Migration command

Run the update-database command

删除*.EntityFrameworkCore/Migrations 文件夹下的所有迁移文件。因为  Pomelo.EntityFrameworkCore.MySql 将添加它自己的配置。

现在已经准备好构建数据库。

将  *.Web.Mvc  设置为启动项目

打开 程序包管理器控制台 ,选择 *.EntityFrameworkCore 项目。

执行 命令 add-migration Initial_Migration

运行  update-database 命令

The MySQL integration is now complete. You can now run your project with MySQL.

到这里,MySQL集成已经完成。你可以在MySQL环境下运行你的项目了。CodeBye 原创,转载请注明链接出处。谢谢。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明ABP Asp.Net Core 集成 MySql 数据库!

abp mysql .net core_ABP Asp.Net Core 集成 MySql 数据库相关推荐

  1. [Abp 源码分析]ASP.NET Core 集成

    点击上方蓝字关注我们 0. 简介 整个 Abp 框架最为核心的除了 Abp 库之外,其次就是 Abp.AspNetCore 库了.虽然 Abp 本身是可以用于控制台程序的,不过那样的话 Abp 就基本 ...

  2. asp.net core集成CAP(分布式事务总线)

    一.前言 感谢杨晓东大佬为社区贡献的CAP开源项目,传送门在此:.NET Core 事件总线,分布式事务解决方案:CAP 以及 如何在你的项目中集成 CAP[手把手视频教程],之前也在工作中遇到分布式 ...

  3. asp.net core 集成 log4net 日志框架

    asp.net core 集成 log4net 日志框架 Intro 在 asp.net core 中有些日志我们可能想输出到数据库或文件或elasticsearch等,如果不自己去实现一个 Logg ...

  4. asp.net core 集成 prometheus

    asp.net core 集成 prometheus Intro Prometheus 是一个开源的现代化,云原生的系统监控框架,并且可以轻松的集成 PushGateway, AlertManager ...

  5. asp.net core 集成JWT

    [什么是JWT] JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案. JWT的官网地址:https://jwt.io/ 通俗地来讲,JWT是能代表用户身份的令牌,可以使用JWT ...

  6. php asp.net core,ASP.NET Core集成微信登录的实例图解

    这篇文章主要介绍了ASP.NET Core集成微信登录的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 工具: Visual Studio 2015 update 3 Asp.Net Co ...

  7. ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core

    前言 原本本节内容是不存在的,出于有几个人问到了我:我想使用ASP.NET Core Identity,但是我又不想使用默认生成的数据库表,想自定义一套,我想要使用ASP.NE Core Identi ...

  8. docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用

    .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...

  9. asp.net core集成CKEditor实现图片上传功能

    背景 本文为大家分享了asp.net core 如何集成CKEditor ,并实现图片上传功能的具体方法,供大家参考,具体内容如下. 准备工作 1.visual studio 2019 开发环境 2. ...

最新文章

  1. 【学术笔记】探索大脑静息态活动中的动态信息
  2. Java基础学习总结(21)——数组
  3. 59. Leetcode 81. 搜索旋转排序数组 II(二分查找-局部有序)
  4. oracle record is locked by another user
  5. 今天突然想到一个问题:地球在转动吗,由东西向西跳与由西向东跳哪个更远...
  6. HDFS High Availability体系介绍(Using the Quorum Journal Manager)
  7. ubuntu14.0.4下安装pycharm
  8. ScaleGestureDetector使用注意事项
  9. 用JAVA制作小游戏——推箱子(一)
  10. c# export server 调用sql_C#调用SQL Server参数过程传参
  11. IE6下实现Width:auto
  12. 分享一个空手反套白狼的骚操作
  13. java弹跳小球程序_用java实现跳动的小球示例代码
  14. 计算机锁屏域策略,域组策略锁屏界面设置不生效
  15. php不显示notice,解决PHP显示Warning和Notice等问题
  16. Maximize The Beautiful Value (前缀和贪心)
  17. 最有效率的⽅法计算2乘以8
  18. 怎么用计算机弹出行星,宇宙模拟器space engine教程2:创建自定义太阳系,包括创建恒星,行星等(上)...
  19. ACwing 基础知识
  20. 不使用Ultra Liberarion软件导出BXL文件的方法

热门文章

  1. elementui分页组件按钮样式修改_Vue使用Elementui修改默认最快方法!
  2. 教资计算机科学与技术教资,教资笔试查成绩啦!广师大未来教师们又前进一步...
  3. 怎么在QQ浏览器上使用微信聊天?
  4. qq浏览器如何进入私密 qq浏览器怎样进入私密
  5. Python排序算法(一)冒泡排序、选择排序、插入排序
  6. ajax post django,Django中的Ajax POST请求失败
  7. Spring Boot jackson配置使用详解
  8. Java IO流之PrintStream分析
  9. python 分类变量转为哑变量_python 虚拟变量
  10. java单位数_java – 优化代码以查找给定数量N的阶乘的单位数