简体   繁体   English

MySQL的实体框架defaultConnectionFactory

[英]Entity Framework defaultConnectionFactory for MySQL

The below configuration works fine when I specify the connectionString name as a parameter to the base constructor. 当我将connectionString名称指定为基础构造函数的参数时,以下配置正常工作。 Because I want to be able to change the default provider later on without recompiling, I want to set it in my app.config instead, but I have no idea what to provide as type for defaultConnectionFactory . 因为我希望以后能够在不重新编译的情况下更改默认提供程序,所以我想在app.config设置它,但我不知道提供什么作为defaultConnectionFactory type

  <connectionStrings>
    <add name="MySQL" providerName="MySql.Data.MySqlClient" connectionString="SERVER=localhost;DATABASE=abc;UID=root;PASSWORD=;" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, EntityFramework"></defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>

Exception: 例外:

Failed to set Database.DefaultConnectionFactory to an instance of the 'MySql.Data.Entity.MySqlConnectionFactory, EntityFramework' type as specified in the application configuration. 无法将Database.DefaultConnectionFactory设置为应用程序配置中指定的“MySql.Data.Entity.MySqlConnectionFactory,EntityFramework”类型的实例。 See inner exception for details. 请参阅内部异常了解详细信

Inner exception (translated, VS is set to English but some messages are still in my language): 内部异常(已翻译,VS设置为英语但某些消息仍为我的语言):

Could not load type "MySql.Data.Entity.MySqlConnectionFactory" in assembly "EntityFramework" 无法在程序集“EntityFramework”中加载“MySql.Data.Entity.MySqlConnectionFactory”类型

The documentation states that the assembly name follows after the colon, thus I also tried MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6 , giving me this exception: 文档说明程序集名称MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6冒号,因此我也尝试了MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6 ,给我这个例外:

Format of the initialization string does not conform to specification starting at index 0. 初始化字符串的格式不符合从索引0开始的规范。

I'm using EF6, MySql.Data & MySql.Data.Entity.EF6 6.8.3.0. 我正在使用EF6,MySql.Data和MySql.Data.Entity.EF6 6.8.3.0。

The name property of the connectionString must be the same as your context. connectionString的name属性必须与您的上下文相同。 This works fine: 这很好用:

  <connectionStrings>
    <add name="NAMEOFYOURCONTEXT" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=abc;Uid=root;Pwd='';" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6"></defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
    </providers>
  </entityFramework>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM