Introduction

While our default templates designed to work with SQL Server, you can easily modify them to work with MySql. In order to do that, you need to follow below steps.

Download Project

Go to http://aspnetboilerplate.com/Templates and download a new project. Select ASP.NET MVC 5.x tab and don't forget to select Entity Framework.

Install MySql.Data.Entity

Then you need to install MySql.Data.Entity nuget package to your .EntityFramework and .Web projects. Installing this nuget package to your .Web project should make necessary changes in your web.config file.

Open your DbContext's configuration class (Configuration.cs) and place below code in it's constructor

SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());

Configure ConnectionString

You need to change your connection string in the web.config file in order to work with your MySql database. An example connection string would be

<add name="Default" connectionString="server=localhost;port=3306;database=sampledb;uid=root;password=***" providerName="MySql.Data.MySqlClient"/>

Re-generate migrations(重新生成迁移)

If you choose "Include module zero?" while downloading your startup template, there will be some migration files included in your project but those files are generated for Sql Server. Delete all migration files in your.EntityFramework project under Migrations folder. Migration files start with a timestamp. A migration file name would be like this "201506210746108_AbpZero_Initial"

After deleting all migration files, select your .Web project as startup project, open Visual Studio's Package Manager Console and select .EntityFramework project as default project in Package Manager Console. Then run below command to add migration for MySql.

如果您选择“包括模块零?”在下载启动模板时,将在项目中包含一些迁移文件,但这些文件是为SQL Server生成的。删除所有迁移文件your.entityframework项目文件夹下的迁徙。迁移文件以一个时间戳开始。迁移文件名会是这样的“201506210746108_abpzero_initial”

删除所有迁移文件,之后选择你。Web项目为启动项目,打开Visual Studio的软件包管理器控制台和选择。EntityFramework项目作为软件包管理器控制台的默认项目。然后运行下面的命令为mysql添加迁移。

Add-Migration "AbpZero_Initial"

Now you can create your database using below command

Update-Database

It is all done, now you can run your project with MySql.

ABP框架系列之二十三:(EF-MySql-Integration-EF-MySql-集成)的更多相关文章

  1. ABP框架系列之二:(Entity Framework Core-实体核心框架)

    Introduction(介绍) Abp.EntityFrameworkCore nuget package is used to integrate to Entity Framework (EF) ...

  2. ABP框架系列之二十:(Dependency-Injection-依赖注入)

    What is Dependency Injection If you already know Dependency Injection concept, Constructor and Prope ...

  3. ABP框架系列之二十七:(Feature-Management-特征管理)

    Introduction Most SaaS (multi-tenant) applications have editions (packages) those have different fea ...

  4. ABP框架系列之二十四:(Email-Sending-EF-电子邮件发送)

    Introduction Email sending is a pretty common task for almost every application. ASP.NET Boilerplate ...

  5. ABP框架系列之二十六:(EventBus-Domain-Events-领域事件)

    In C#, a class can define own events and other classes can register it to be notified when something ...

  6. ABP框架系列之二十二:(Dynamic-Web-API-动态WebApi)

    Building Dynamic Web API Controllers This document is for ASP.NET Web API. If you're interested in A ...

  7. ABP框架系列之二十八:(Handling-Exceptions-异常处理)

    Introduction This document is for ASP.NET MVC and Web API. If you're interested in ASP.NET Core, see ...

  8. ABP框架系列之二十五:(Embedded-Resource-Files-嵌入式资源文件)

    Introduction ASP.NET Boilerplate provides an easy way of using embedded Razor views (.cshtml files) ...

  9. ABP框架系列之二十九:(Hangfire-Integration-延迟集成)

    Introduction Hangfire is a compherensive background job manager. You can integrate ASP.NET Boilerpla ...

随机推荐

  1. Spring MVC 支持的原生API参数

    HttpServletRequest HttpServletResponse HttpSession java.security.Principal Local InputStream OutputS ...

  2. C# 通用方法

    一. /// <summary> /// 删除字符串中的中文 /// </summary> public static string Delete(string str) { ...

  3. 通过http方式关闭和重启Jenkins

    Jenkins关闭和重启实现方式.   1.关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit.例如我jenkins的地址http://localhost:8080/, ...

  4. 锋利的BFC

    在初学前端的时候,我们会经常碰到各种各样的布局问题,尤其当使用浮动的时候,然而学习了BFC之后,其中的一些怪异现象,也因此成为理所当然,会有一种拨开云雾的快感. 下面简单介绍下BFC,究竟什么是BFC ...

  5. 类定义,创建/销毁OC对象

    类定义 1 OC类分为2个文件,一个是.h文件,一个是.m文件: 2 .h文件存放类.函数声明: 3 .m文件类的具体实现: 4 类声明使用关键字@interface.@end来声明: 5 类实现使用 ...

  6. 如何判断int类型相等

    int  a=10: int b=10: a==b  通过==判断两个int值是否相等. if(a==b){ 相等 }else{ 不相等 }

  7. DOM 练习

    练习一: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  8. C语言实现24点程序

    一.简介 本程序的思想和算法来自于C语言教材后的实训项目,程序通过用户输入四个整数计算出能够通过加减乘除得到数字24的所有表达式,程序的设计有别于一般通过穷举实现的方式,效率得到提高.算法介绍如下: ...

  9. keras—多层感知器MLP—MNIST手写数字识别

    一.手写数字识别 现在就来说说如何使用神经网络实现手写数字识别. 在这里我使用mind manager工具绘制了要实现手写数字识别需要的模块以及模块的功能:  其中隐含层节点数量(即神经细胞数量)计算 ...

  10. rapidjson使用

    Value构造 Value对象最好先声明后初始化,如果声明直接初始化可能出错. rapidjson::Value a; a = val[i]; Value传参 Value传参,最好显式使用右值,如st ...