vs2017 Mariadb/mysql之旅

记录vs2017使用 ef6+mysql的开发 填坑之旅。我的环境 vm+centos7+ docker-ce+mariadb+vs2017

总的原则是MySql.Data.Entity 要和 mysql-connector-net 版本对应。

首先看下nuget支持的 MySql.Data.Entity版本 

而事实上证明 6.10.6版本有bug。可能会有各种错误:生成实体向导会报错 ,未将对象引用到对象实例,找不到数据源,您的项目引用了最新实体框架;但是,找不到数据连接所需的与版本兼容的实体框架数据提供程序。请退出此向导,安装兼容提供程序,重新生成您的项目,然后再执行操作。

折腾了很久才改为 6.9.11版本,mysql-connector-net也使用6.9.11 .一切ok. 看来最新版的 稳定版的也不可靠呀。如果还有问题的话看下 MySQL Connector/ODBC 有没有安装。

使用Codefirst 

使用nuget控制台执行 Add-Migration报错

 No MigrationSqlGenerator found for provider 'MySql.Data.MySqlClient'. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators.

解决方法: 在 Configuration构造函数里面添加 this.SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());

public Configuration()
{
AutomaticMigrationsEnabled = false;
this.SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}

生成的是 库名.表名 生成的类特性 Table(库名.表名),暂时没好办法 手动去掉前缀

附件 下载地址:

1.    Connector/Net 6.9.11

2.  MySQL for Visual Studio 1.2.7

3. Connector/ODBC 5.3.10

原文地址:https://www.cnblogs.com/wtujvk/p/8513839.html