I have a .NET Core project (targeting .NET 4.6) where I have to use both EF Core and EF 6. Since I'm also using MySQL, my project.json
looks something like this:
{
...
"dependencies": {
"EntityFramework": "6.1.3", // For EF 6
"MySql.Data.Entity": "6.9.9", // For EF 6 and MySQL
"Pomelo.EntityFrameworkCore.MySql": "1.1.0", // For EF Core
...
},
"frameworks": {
"net461": {}
},
...
}
The problem is when I try to use the class MySqlConnection
like this:
var connection = new MySqlConnection(connectionString);
I get the following error:
The type 'MySqlConnection' exists in both
'MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' and
'MySqlConnector, Version=0.7.2.0, Culture=neutral, PublicKeyToken=null'
Is there a way for me to specify exactly from which library I want to use MySqlConnection
, or is there any other way to solve this?
These are my constraints:
- I need EF Core since we use
ASP.NET Core Identity
(and other .NET Core libraries using only EF Core) - I need EF 6 since we found that at the moment there are no EF Core implementations for MySQL that are good enough for all our needs.
- Since we are using MySQL, I need to use
MySql.Data.Entity
for EF 6 andPomelo.EntityFrameworkCore.MySql
for EF Core. We've tried to use other libraries for EF Core, but they come with a lot of bugs. We found Pomelo to be the most stable.
EDIT:
I think the reason is that Pomelo.EntityFrameworkCore.MySql
references MySqlConnector
which has the namespace/class MySql.Data.MySqlClient.MySqlConnection
, and so does MySql.Data.Entity
.