2016-10-26 91 views
1

我想使用我的模型,並從中創建一個數據庫。當我嘗試基於該模型,我收到以下錯誤生成一個數據庫:EntityFramework 6將無法與MySql

Running transformation: System.InvalidOperationException: The SSDL generated by the activity called 'CsdlToSsdlAndMslActivity' is not valid and has the following errors:
No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

 
    at Microsoft.Data.Entity.Design.DatabaseGeneration.EdmExtension.CreateAndValidateStoreItemCollection(String ssdl, Version targetFrameworkVersion, IDbDependencyResolver resolver, Boolean catchThrowNamingConflicts) 
    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 
    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

下面包含我的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> 

我知道這個問題是與MySql.Data.MySqlClient基於錯誤消息,但我似乎無法弄清楚它想要我做什麼。我已將MySql.Data,MySql.Data.Entity.EF6EntityFramework添加到項目中。

任何人都知道如何解決這個問題?

+0

您的EF代碼是否位於程序入口點的不同程序集/項目中?您可能需要爲您的入口點項目添加對「MySq.Data.MySqlClient」的程序集引用,並確保您的App.config內容位於入口點項目中,而不僅僅是庫項目。 – Dai

+0

我的EF代碼與我的程序入口點位於同一個項目中。 'App.config'也是。 – darophi

回答

0

在此之前,我面臨同樣的問題。我設法通過創建一個全新的項目來解決它。

  1. 轉到Manage NuGet Packages,安裝EntityFrameworkMySql.ConnectorNET.DataMySql.ConnectorNET.Entity

  2. 使用連接字符串作爲這裏<add name="SomeDatabase" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=example;uid=hello;password=user"/>

  3. 所示添加[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]中的DbContext類。