简体   繁体   English

EntityFramework 6不适用于MySql

[英]EntityFramework 6 won't work with MySql

I am trying to use my model and create a database from it. 我正在尝试使用我的模型并从中创建数据库。 When i try to generate a database based on the model i get the following error: 当我尝试基于模型生成数据库时,我收到以下错误:

Running transformation: System.InvalidOperationException: The SSDL generated by the activity called 'CsdlToSsdlAndMslActivity' is not valid and has the following errors: 运行转换:System.InvalidOperationException:由名为“CsdlToSsdlAndMslActivity”的活动生成的SSDL无效,并且具有以下错误:
No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. 没有为ADO.NET提供程序找到具有不变名称“MySql.Data.MySqlClient”的实体框架提供程序。 Make sure the provider is registered in the 'entityFramework' section of the application config file. 确保提供程序已在应用程序配置文件的“entityFramework”部分中注册。 See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. 有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882

\n   at Microsoft.Data.Entity.Design.DatabaseGeneration.EdmExtension.CreateAndValidateStoreItemCollection(String ssdl, Version targetFrameworkVersion, IDbDependencyResolver resolver, Boolean catchThrowNamingConflicts) at Microsoft.Data.Entity.Design.DatabaseGeneration.EdmExtension.CreateAndValidateStoreItemCollection(String ssdl,Version targetFrameworkVersion,IDbDependencyResolver resolver,Boolean catchThrowNamingConflicts)\n   at Microsoft.VisualStudio.TextTemplatingFED2D73CEED00C99E8A0A14FA9AE33EAFFDF3CAAFEE9E04D21CC913F1C5C88D960592C81A433C11663E61FD5459CF679CFD9B7275B72CA8BFB8D753DBB9FDDE3.GeneratedTextTransformation.get_Store() in C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Entity Framework Tools\\Templates\\Includes\\GenerateTSQL.Utility.ttinclude:line 57 在Microsoft.VisualStudio.TextTemplatingFED2D73CEED00C99E8A0A14FA9AE33EAFFDF3CAAFEE9E04D21CC913F1C5C88D960592C81A433C11663E61FD5459CF679CFD9B7275B72CA8BFB8D753DBB9FDDE3.GeneratedTextTransformation.get_Store()在C:\\ Program Files文件(x86)的\\微软的Visual Studio 14.0 \\ Common7 \\ IDE \\扩展\\微软\\实体框架工具\\模板\\包括\\ GenerateTSQL.Utility.ttinclude:行57\n   at Microsoft.VisualStudio.TextTemplatingFED2D73CEED00C99E8A0A14FA9AE33EAFFDF3CAAFEE9E04D21CC913F1C5C88D960592C81A433C11663E61FD5459CF679CFD9B7275B72CA8BFB8D753DBB9FDDE3.GeneratedTextTransformation.TransformText() in C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Entity Framework Tools\\DBGen\\SSDLToSQL10.tt:line 84 C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Entity Framework Tools\\Templates\\Includes\\GenerateTSQL.Utility.ttinclude 57 在Microsoft.VisualStudio.TextTemplatingFED2D73CEED00C99E8A0A14FA9AE33EAFFDF3CAAFEE9E04D21CC913F1C5C88D960592C81A433C11663E61FD5459CF679CFD9B7275B72CA8BFB8D753DBB9FDDE3.GeneratedTextTransformation.TransformText()在C:\\ Program Files文件(x86)的\\微软的Visual Studio 14.0 \\ Common7 \\ IDE \\扩展\\微软\\实体框架工具\\ DBGEN \\ SSDLToSQL10.tt:行84 C:\\程序文件(x86)\\ Microsoft Visual Studio 14.0 \\ Common7 \\ IDE \\ Extensions \\ Microsoft \\ Entity Framework Tools \\ Templates \\ Includes \\ GenerateTSQL.Utility.ttinclude 57 

The following contains my App.config if that is of any help: 如果有任何帮助,以下包含我的App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="SomeDatabase" providerName="MySql.Data.MySqlClient" connectionString="password=user;server=192.168.0.114;uid=hello;database=example;persistsecurityinfo=True;" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"></assemblyBinding>
  </runtime>
</configuration>

I know the issue is with the MySql.Data.MySqlClient based on the error message, but i can't seem to figure out what it wants me to do. 我知道问题是基于错误消息的MySql.Data.MySqlClient ,但我似乎无法弄清楚它希望我做什么。 I have added MySql.Data , MySql.Data.Entity.EF6 and EntityFramework to the project. 我已将MySql.DataMySql.Data.Entity.EF6EntityFramework添加到项目中。

Anyone knows how to fix this issue? 任何人都知道如何解决这个问题?

I was facing the same problem before this. 在此之前我遇到了同样的问题。 I manage to solve it by creating a whole new project. 我设法通过创建一个全新的项目来解决它。

  1. Go to Manage NuGet Packages , install EntityFramework , MySql.ConnectorNET.Data and MySql.ConnectorNET.Entity . 转到Manage NuGet Packages ,安装EntityFrameworkMySql.ConnectorNET.DataMySql.ConnectorNET.Entity

  2. Use the connection string as shown here <add name="SomeDatabase" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=example;uid=hello;password=user"/> 使用此处所示的连接字符串<add name="SomeDatabase" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=example;uid=hello;password=user"/>

  3. Add [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] in DbContext class. 在DbContext类中添加[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]

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

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