简体   繁体   English

EntityFramework错误

[英]EntityFramework Error

  1. New Project - Class Library 新项目-类库

  2. Guget Packages - Install-Package EntityFramework, Install-Package MySql.Data, Install-Package MySql.Data.Entities, Install-Package MySql.Web Guget软件包-安装软件包EntityFramework,安装软件包MySql.Data,安装软件包MySql.Data.Entities,安装软件包MySql.Web

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

  4. Add New Item - ADO.NET Entity Data Model 添加新项-ADO.NET实体数据模型

  5. Empty EF Designer - Finish 空的EF设计器-完成

  6. Right Click on the model properties and then DDL Generation Template to SSDLToMySQL.tt 右键单击模型属性,然后单击“ DDL生成模板”到SSDLToMySQL.tt

  7. Sample entity added 样本实体已添加

  8. Build Solution 建立解决方案

  9. Right Click- Generate Database from Model 右键单击-从模型生成数据库

  10. Select Data Connection and hit next. 选择数据连接,然后单击下一步。

Then the window close and nothing happen. 然后,窗口关闭,什么也没有发生。

Adding References Using NuGet Versus an Extension SDK 使用NuGet和扩展SDK添加参考

Install the EF6 NuGet package 安装EF6 NuGet软件包

You need to upgrade to the new Entity Framework 6 runtime. 您需要升级到新的Entity Framework 6运行时。

Right-click on your project and select Manage NuGet Packages... 右键单击您的项目,然后选择管理NuGet软件包...。

Under the Online tab select EntityFramework and click Install 在“联机”选项卡下,选择EntityFramework,然后单击“安装”。

Note: If a previous version of the EntityFramework NuGet package was installed this will upgrade it to EF6. 注意:如果安装了EntityFramework NuGet程序包的早期版本,它将升级到EF6。

Checklist: 清单:

  1. EF5 is built into the core of .NET 4.5, whereas EF6 has been shifted out, and is open source. EF5内置于.NET 4.5的核心中,而EF6已被移出,并且是开源的。

    • This means that you must add the new EF6 assemblies to all of the relevant projects in the solution, in particular the entry project. 这意味着您必须将新的EF6程序集添加到解决方案中的所有相关项目中,尤其是输入项目。
    • This means that you must remove assembly System.Entity from all projects, as this refers to EF5. 这意味着您必须从所有项目中删除程序集System.Entity,因为这是指EF5。
  2. EF5 has a single .dll "EntityFramework.dll", whereas EF6 has two .dlls: EF5具有单个.dll“ EntityFramework.dll”,而EF6具有两个.dll:

    • EntityFramework 实体框架
    • EntityFramework.SqlServer EntityFramework.SqlServer
  3. EF6 requires changes to app.config. EF6需要更改app.config。 The best way to make these changes is to right click on the Solution, select "Manage NuGet Packages for Solution", search for "EntityFramework" and install v6.1.0 of Entity Framework into all of the relevant projects, in particular the entry project. 进行这些更改的最佳方法是右键单击“解决方案”,选择“管理解决方案的NuGet程序包”,搜索“ EntityFramework”,然后将Entity Framework v6.1.0安装到所有相关项目中,尤其是进入项目。 Make sure you uninstall any NuGet packages for EF5 Framework from all projects. 确保从所有项目中卸载所有用于EF5框架的NuGet软件包。 This will automatically update your app.config files so they are correct. 这将自动更新您的app.config文件,使它们正确无误。
  4. Examine all app.config files for references to EF5, and remove them. 检查所有app.config文件中对EF5的引用,然后将其删除。
  5. The namespaces have changed: 名称空间已更改:

    • Remove C# lines "using System.Data.EntityClient;", which is an EF5 reference. 删除“使用System.Data.EntityClient;”的C#行,这是EF5引用。
    • Add C# line"using System.Data.Entity.Core.EntityClient;" 添加C#行“使用System.Data.Entity.Core.EntityClient;” which is the correct for EF6. 这对于EF6是正确的。

This checklist is a Community Wiki, 此清单是社区Wiki,

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

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