EF6和MySQL从Model生成数据库 [英] EF6 and MySQL Generate Database from Model

查看:171
本文介绍了EF6和MySQL从Model生成数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过在网络上找到的每个解决方案,没有成功。我不断得到错误:

I've tried every solution I've found on the web with no success. I continually get the error:

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.

我有一个空的控制台项目和一个非常基本的模型来测试。通过NuGet软件包控制台,我执行:安装包MySQL.Data.Entities 安装了EF6,$ code> MySQL.Data 和 MySQL.Data.Entities 并挂接所有的引用,并将相关的DLL复制到 bin / Debug 文件夹中

I have an empty Console project and a very basic model to test this with. Through the NuGet Package Console I'd executed: Install-Package MySQL.Data.Entities which installed EF6, MySQL.Data and MySQL.Data.Entities and hooked up all the references and copied the relevant DLL's into the bin/Debug folder.

我在以下(列出的整个配置文件)中连接提供商

I wired up the provider in the following (entire config file listed)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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>
</configuration>

据我所知,我已经提供了注册。我也更新了最新的MySQL连接器。我在哪里出错?

As far as I can tell I have the provider registered. I have the latest MySQL connector updated as well. Where am I going wrong?

推荐答案

为了支持全面的功能,EF Designer需要3件事:

To support full functionality EF Designer requires 3 things:


  • EF运行时提供程序(您似乎拥有)

  • 数据库的DDEX提供程序 - DDEX是VS抽象数据库和结果可以与任何数据库通信。请注意,这不是EF特定的,但EF Designer依赖它(再次,您似乎有其他方式,否则您将无法选择MySQL连接)

  • 其他组件(T4模板/ Workflow活动)支持Model First流程 - 这些是EF特定的,但通常作为DDEX提供程序的一部分进行安装 - 您似乎缺少这个或您没有选择特定于您的提供商的T4模板/工作流程edmx文件并转到属性窗口,从DDL生成角度来看,有两个有趣的选项 - 数据库生成工作流和DDL生成模板,点击下拉菜单,看看是否可以选择一些特定于MySQL的)

  • EF runtime provider (you seem to have it)
  • DDEX provider for your database - DDEX is the way VS abstracts databases and as a result can talk to any database. Note that this is not something that is EF specific but EF Designer relies on it (again you seem to have it otherwise you would not be able to select MySQL connection)
  • Additional components (T4 templates/Workflow activities) required to support Model First flow - these are EF specific but typically installed as part of the DDEX provider - you seem to be missing this or you did not select the T4 template/workflow specific to your provider (open the edmx file and go to the properties window there are two options there that are interesting from DDL generation perspective - the "Database Generation Workflow" and the "DDL Generation Template". Click the dropdowns to see if you can select something that is MySQL specific)

因为你似乎没有或使用MySQL的工作流/ T4(注意我不知道这是不是因为你没有选择正确的T4 /工作流程(见上文),或者MySQL DDEX不支持这个或安装程序离子是因为任何原因破碎)EF Designer正在使用用于Sql Server的默认工作流。默认工作流程依赖于能够在默认路径中找到EF提供程序(对于SqlServer和SqlServerCe),但MySQL的提供程序不存在 - 因此出现错误。请注意,用于创建DDL的工作流程和T4模板是特定于提供程序的,因此即使您将MySQL提供程序复制到默认路径也不会真正有效 - 您将使用MySQL类型获得SQL Server特定SQL脚本的特殊结果。

Because you don't seem to have or use the workflow/T4 for MySQL (note I don't know if this is because you did not select the correct T4/workflow (see above) or MySQL DDEX does not support this or the installation is for whatever reason broken) EF Designer is using the default workflow which is for Sql Server. The default workflow relies on being able to find EF providers (for SqlServer and SqlServerCe) in the default path but the provider for MySQL is not there - hence the error. Note that the workflow and T4 templates for creating DDL are provider specific so even if you copied the MySQL provider to the default path it would not really work - you would get a peculiar result of SQL Server specific SQL Script using MySQL types.

我们有一个错误改进通过提供更好的指导,而不仅仅是调用我们知道的默认DDL生成将不起作用,这有一点点。您还可以在此错误中找到一些详细信息。

We have a bug on improving this a little bit by providing a better guidance instead of just invoking the default DDL generation which we know will not work. You can also find some details in this bug.

我建议检查您使用的MySQL组件是否支持Model First。一个替代方案只是转向Code First,只需要您已经生成DDL的EF运行时提供者。

I would suggest checking if MySQL components you are using do support Model First. An alternative would be just to move to Code First which only requires the EF runtime provider you already have to generate the DDL.

这篇关于EF6和MySQL从Model生成数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆