【发布时间】:2011-09-09 00:09:44
【问题描述】:
我目前有一个应用程序,它首先使用 EF 数据库,它是针对 SQL Server 数据库构建的。我希望能够连接到 MSSQL 或 MySQL。
我假设通过使用 EF,我可以将连接字符串更改为指向 MySQL,但是,当我这样做时,我收到以下错误:
无法转换类型的对象 'MySql.Data.MySqlClient.MySqlConnection' 输入 'System.Data.SqlClient.SqlConnection'。
还需要哪些其他步骤才能使 EF 与 MySQL 和 MSSQL 一起使用。
更新: 连接字符串:
<add name="EntityConnString" connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=MySql.Data.MySqlClient;
provider connection string="server=localhost;User Id=root;password=password;Persist Security Info=True;database=mydb;Connection Protocol=NamedPipe"" providerName="System.Data.EntityClient" />
【问题讨论】:
-
你能用虚拟数据发布你的连接字符串吗?
-
添加了连接字符串。
-
您是否对生成的代码进行了任何更改?你的 tt 文件或一切都是默认的?您的连接字符串很好。但也请查看您的 edmx 内部,它可能包含对存储命名空间 (ssdl) 中 mssql 的一些引用。
标签: mysql sql-server entity-framework database-first