ABP框架系列之二十三:(EF-MySql-Integration-EF-MySql-集成)
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-集成)的更多相关文章
- ABP框架系列之二:(Entity Framework Core-实体核心框架)
Introduction(介绍) Abp.EntityFrameworkCore nuget package is used to integrate to Entity Framework (EF) ...
- ABP框架系列之二十:(Dependency-Injection-依赖注入)
What is Dependency Injection If you already know Dependency Injection concept, Constructor and Prope ...
- ABP框架系列之二十七:(Feature-Management-特征管理)
Introduction Most SaaS (multi-tenant) applications have editions (packages) those have different fea ...
- ABP框架系列之二十四:(Email-Sending-EF-电子邮件发送)
Introduction Email sending is a pretty common task for almost every application. ASP.NET Boilerplate ...
- ABP框架系列之二十六:(EventBus-Domain-Events-领域事件)
In C#, a class can define own events and other classes can register it to be notified when something ...
- ABP框架系列之二十二:(Dynamic-Web-API-动态WebApi)
Building Dynamic Web API Controllers This document is for ASP.NET Web API. If you're interested in A ...
- ABP框架系列之二十八:(Handling-Exceptions-异常处理)
Introduction This document is for ASP.NET MVC and Web API. If you're interested in ASP.NET Core, see ...
- ABP框架系列之二十五:(Embedded-Resource-Files-嵌入式资源文件)
Introduction ASP.NET Boilerplate provides an easy way of using embedded Razor views (.cshtml files) ...
- ABP框架系列之二十九:(Hangfire-Integration-延迟集成)
Introduction Hangfire is a compherensive background job manager. You can integrate ASP.NET Boilerpla ...
随机推荐
- mouseenter 事件
定义和用法 当鼠标指针穿过元素时,会发生 mouseenter 事件. 该事件大多数时候会与 mouseleave 事件一起使用. mouseenter() 方法触发 mouseenter 事件,或规 ...
- Linux下基于官方源代码RPM包构建自定义MySQL RPM包
rpmbuild时不要以root用户执行! 方法一: 1.首先安装rpmbuild #yum install rpm-build gcc gcc-c++ cmake bison ncurses-dev ...
- Kotlin语言学习笔记(4)
函数 // 函数定义及调用 fun double(x: Int): Int { return 2*x } val result = double(2) // 调用方法 Sample().foo() / ...
- Winform 两个窗体通讯 一个窗体调用另一个窗体的方法
主要用到 委托 和 注册事件. 功能:点击form1的按钮,改变form2的label文本
- godaddy nginx https 配置
一. 生成秘钥key,运行: $ openssl genrsa -des3 -out server.key 2048 1 会有两次要求输入密码,输入同一个即可 输入密码 然后你就获得了一个server ...
- Java的indexOf返回的是第一个匹配到的字符的索引位置,substring(a,b)获得字符串的一部分内容
背景:我要实现一个功能,需要匹配两个字符串是否有相同的字符,所以就写了下面一个小方法,定义两个字符串a和b,循环遍历 b,如果a中有b的子串就将匹配数量num+1 遇到的问题:开始判断字符串中是否 ...
- oracle改变表中列的编码
ALTER TABLE table_name CHANGE `name` `name` VARCHAR(255) CHARACTER SET utf8;
- avg(xxxxxx)什么时候能独自出现?
avg(xxxxxx)是作为求一组数据的平均数,需要有这组数据的总数和个数,所以通常配合着group by来使用, 比如: SELECT ID, AVG(GRADE) AS 平均数 FROM TEST ...
- 57. Insert Interval (Array; Sort)
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- Mysql优化性能优化21条
今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...