2014-01-08 14 views
5

EF noobとして、開発用コンピュータにインストールしたMySql Server 5.6でEntity Framework 6 Code Firstを使用しようとしています。MySql Connector EF6

私は非常に小さなテストコンソールプロジェクトを作成しました。私はNuGetパッケージを追加しました:

  1. EntityFramework 6.0.2
  2. をMySql.Data
  3. MySql.Data.Entities.EF6

を私のApp.configファイルは、次のようになります。

<entityFramework> 
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider> 
    </providers> 
</entityFramework> 

Aは2つのクラスを有する。

あるMyContext:

public class MyContext : DbContext 
{ 
    public MyContext(DbConnection connection) 
     : base(connection, true) 
    { 
    } 

    public DbSet<MyEntity> MyEntities { get; set; } 
} 

MyEntity:

public class MyEntity 
{ 
    [Key] 
    public int Id { get; set; } 

    public string Name { get; set; } 
} 

私の主な方法は次のようになります。私はそれを実行すると

static void Main(string[] args) 
{ 
    using (MySqlConnection conn = new MySqlConnection("Server=127.0.0.1;Database=calibrationtest;Uid=calibration;Pwd=*******")) 
    { 
     using (MyContext context = new MyContext(conn)) 
     { 
      context.MyEntities.Add(new MyEntity() 
      { 
       Name = "1234" 
      }); 

      context.SaveChanges(); 
     } 
    } 
} 

私はSystem.NotSupportedExceptionを得る:

Unable to determine the provider name for provider factory of type 
'MySql.Data.MySqlClient.MySqlClientFactory'. Make sure that the 
ADO.NET provider is installed or registered in the application config 

MySql.Data.Myを追加しようとしましたApp.configファイルにSqlClient.MySqlClientFactory:

<provider invariantName="MySql.Data.MySqlClient.MySqlClientFactory" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"></provider> 

しかし、その後、私はEntity.Coreバグに到着:私は間違って

The 'Instance' member of the Entity Framework provider type 
'MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, 
Culture=neutral, PublicKeyToken=c5687fc88969c44d' did not return an object 
that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. 

何をしているのですか?私はNuGetパッケージ(MySql.DataとMySql.Data.Entities.EF6)

を削除しようとした

EDIT

は、それから私は、新しいバージョンdirectly from MySqlをインストールし、現在上記のテストコードが正常に実行されますか?

答えて

5

私は正確に同じ問題に遭遇した、

このような
<system.data> 
    <DbProviderFactories> 
     <remove invariant="System.Data.SQLite" /> <add name="SQLite Data Provider" description=".Net Framework Data Provider for SQLite" invariant="System.Data.SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /> 
     <remove invariant="MySql.Data.MySqlClient" /><add name="MySQL" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/> 
    </DbProviderFactories> 
    </system.data> 

    <entityFramework> 
    <providers> 
     <provider invariantName="System.Data.SQLite"  type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /> 
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>  
    </providers> 
    </entityFramework> 
+0

これは私のコードでは何も変わりません。私は私がこの問題をどのように回避したかを編集しました。 – smerlung

0

を両方のconfigセクションを維持する必要があります。 は、以下のNuGetパッケージを使用してそれを修正するために管理:私もEF6.1と、このエラーを得ていた

EntityFramework 6.1.0 
MySql.ConnectorNET.Data 6.8.3.2 
MySql.ConnectorNET.Entity 6.8.3.2 
1

:「型「MySql.Data.MySqlClientのプロバイダ・ファクトリのプロバイダ名を判別できません。 "

これは、以前のバージョンのMySQL.Data(6.7.4)を参照するバインディングリダイレクトが原因であることが判明しました。これは、「MySqlClientFactory」に含まれています。 EF6はサポートしていません。私がそれを変更した後:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-6.8.3.0" newVersion="6.8.3.0" /> 
    </dependentAssembly> 
</assemblyBinding> 

エラーはなくなりました。

関連する問題