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. delphi android路径 TPath 文件路径,文件管理

    获取Android相关文档路径 delphi 新路径.文件功能 IOUtils单元,文件路径,文件管理 http://docwiki.embarcadero.com/RADStudio/Berlin/ ...

  2. 前端-CSS-10-定位

    <!-- 定位有三种: 1.相对定位 2.绝对定位 3.固定定位 这三种定位,每种定位都暗藏玄机,所以我们要一一单讲 position:relative; position:absolute; ...

  3. mysql启动报错 The server quit without updating PID file

    [root@uz6542 data]# /etc/init.d/mysqld startStarting MySQL... ERROR! The server quit without updatin ...

  4. JDBC之使用配置文件链接数据库

    写在前面 JDBC以一种统一的方式来对各种各样的数据库进行存取,JDBC为开发人员隐藏了不同数据库的不同特性.程序员开发时,知道要开发访问数据库的应用,于是将一个对应数据库的JDBC驱动程序类的引用进 ...

  5. 基元线程同步构造之 Mutes(互斥体)

    互斥体实现了“互相排斥”(mutual exclusion)同步的简单形式(所以名为互斥体(mutex)). 互斥体禁止多个线程同时进入受保护的代码“临界区”(critical section). 因 ...

  6. 关于使用service的上下文和activity来读取sharedpreferences的同步问题

    比如我用activity 对象 mainactivity 的context 获取了sharedpreferences对象,并putString(context, "demo", & ...

  7. 4、注解反射生成SQL语句

    .任务说明         ①有一张用户表,字段包括:用户ID.用户名.昵称.年龄.性别.所在城市.邮箱.手机号:         ②使用java注解来对用户表的每个字段或字段的组合条件进行动态生成S ...

  8. LocalDateTime json格式化

    参考https://www.cnblogs.com/xiaozhang9/p/jackson.html?utm_source=itdadao&utm_medium=referral <d ...

  9. tmpFile.renameTo(classFile) failed解决

    完整异常: 严重: Servlet.service() for servlet [bjbr] in context with path [/HerPeisWechat] threw exception ...

  10. 84直方图最大矩形覆盖 · Largest Rectangle in Histogram

    [抄题]: Given n non-negative integers representing the histogram's bar height where the width of each ...