首页 > 技术文章 > Entity Framework Code First(Mysql)

xmai 2017-05-11 09:34 原文

 

1、添加NuGet包

引用NuGet包:EntityFramework6.1.3、MySql.Data.Entity6.9.8

 

2、修改配置

SqlServer配置:

<add name="WorkflowEntities" connectionString="data source=.;Database=demodb;UID=sa;Password=sa" providerName="System.Data.SqlClient" />

 

Mysql配置:

<add name="MyContext" connectionString="Data Source=127.0.0.1;port=3306;Initial Catalog=mysqlDemoDb;user id=root;password=root;" providerName="MySql.Data.MySqlClient"/>

 

3、启动迁移

 

Enable-Migrations

 

4、修改迁移生成的Config.cs

关闭自动迁移、修改生成器

public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());//设置Sql生成器为Mysql的
        }

 

至此其他操作和sqlserver类同

 

推荐阅读