在Microsoft Visual Studio 2013的WinForms中为MySql(C#)启用实体框架6 [英] Enable Entity Framework 6 for MySql (C#) in WinForms of Microsoft Visual Studio 2013

查看:165
本文介绍了在Microsoft Visual Studio 2013的WinForms中为MySql(C#)启用实体框架6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我知道Entity Framework是另一种使用Dataset或DataReader访问数据库的方法,那么我试图让MVC 2013中的MySql数据库服务器实现Entity Framework 6。

Yesterday I knew that Entity Framework is another method to access database beside using Dataset or DataReader,then I tried to make Entity Framework 6 work for my MySql database server in MVS 2013.

我用.Net FrameWork 4.5.1打开一个WinForms。 (所以我只有App.config,但项目中没有app / web配置)
我安装了 mysql-installer-community-5.7.3.0-m13.msi

I open a WinForms with .Net FrameWork 4.5.1. (so I only have App.config but no app/web config in the project) After I installed mysql-installer-community-5.7.3.0-m13.msi and

通过

工具菜单 - >图书馆包管理器 - >管理NuGet包
解决方案... - >在线 - >(搜索)EntityFramework(请注意此版本
包应该是版本6.0.2,如果没有,然后单击
更新 - > EntityFramework更新)

TOOLS menu -> Library Package Manager -> Manage NuGet Packages for Solution... -> Online -> (Search) EntityFramework (beware of version of this package and it should be version 6.0.2, if not then click Updates -> EntityFramework to update)

当我尝试添加ADO.NET实体数据模型通过

When I tried to add ADO.NET Entity Data Model via


右键单击项目 - >添加 - >新项目 - > ADO.NET实体数据模型
- >从数据库生成 - >新连接
- >数据源: - >更改...-> MySQL数据库
- >使用服务器IP,用户名和密码填写服务器名称
- >选择数据库名称 - >测试连接 - >确定

Right click Project -> Add -> New Item -> ADO.NET Entity Data Model -> Generate from Database -> New Connection -> Data sources: -> Change...-> MySQL Database -> Fill in the Server name with server IP, Username and Password -> Choose the Database name-> Test Connection -> OK

然后生成实体连接字符串 - >勾选将App.Config中的实体连接设置保存为 - >下一步> - >

Then Entity Connection string is generated -> Tick Save entity connection settings in App.Config as -> Next> ->

要使用哪个版本的Entity Framework?
有选项实体框架6.0,但您不能使用它,因为

Which version of Entity Framework do you want to use? Have option Entity Framework 6.0 but you cannot use it because


您的项目引用最新版本的实体框架;
然而,与您的数据连接无法找到与此
版本兼容的实体框架数据库提供程序。退出此向导,
安装兼容的提供程序,并在
执行此操作之前重建项目

"Your project references the latest version of Entity Framework; however, an Entity Framework database provider compatible with this version could not be found for your data connection. Exit this wizard, install a compatible provider, and rebuid your project before performing this action".

如何解决?

顺便说一句,如果您在Nuget Package中安装了Entity Framework 5,那么您可能在这里选择了Entity Framework 5.0,您可能会使用Entity Framework 5而不是版本6。

By the way , if you install Entity Framework version 5 in Nuget Package then you might have option Entity Framework 5.0 here and you might success to use Entity Framework 5 but not the version 6.

推荐答案

首先,我们甚至不需要安装mysql-installer- 社区 -5.7 .3.0-m13.msi。

First of all, we don't even need to install the mysql-installer-community-5.7.3.0-m13.msi.


  1. 安装最新的 mysql-visualstudio-plugin

  2. 安装最新的 mysql-connector-net

  3. 新的C#.Net 4.5 框架WinForms对于 4.0 ,它应该基于实体框架6支持.NET 4.0?

  4. 安装4 Nuget软件包(按照序列,如果在EntityFramework之前安装Mysql.Data.Entities,则将解决依赖关系并安装EntityFramework 6.0.2 ,但我们需要的是EntityFramework 6.1.0

  1. Install the latest mysql-visualstudio-plugin
  2. Install the latest mysql-connector-net
  3. New C# .Net 4.5 Framework WinForms (for 4.0 it should work based on Does Entity Framework 6 support .NET 4.0? )
  4. Install 4 Nuget Packages (follow sequence, if you install Mysql.Data.Entities before EntityFramework, it will resolve dependency and install EntityFramework 6.0.2 but what we need is EntityFramework 6.1.0)




EntityFramework

EntityFramework

Mysql.Data

Mysql.Data

Mysql.Data .Entities

Mysql.Data.Entities

Mysql.Web

Mysql.Web

5.如果你有>标签实体框架在 App.config 中,请在标签启动后将其注释并在App.config中插入新的标签entityFramework

5.If you have tag entityFramework in App.config, please comment it and insert new tag entityFramework in App.config after tag startup

  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>

6.添加 ADO.NET实体数据模型(如问题所述)

6.Add ADO.NET Entity Data Model (as mentioned in question)

7.在实体连接字符串生成(如上所述)和勾选App.Config中的实体连接设置之后,点击下一步

7.After Entity Connection string is generated (as mentioned in question) and Tick Save entity connection settings in App.Config as then click Next

8.选择您的数据库对象和设置(表,视图或存储过程和函数)(没有哪个版本的实体框架?,因为我只有一个实体框架6.0提供者,所以直接跳过选择,如果我唯一的提供者是有效的)

8.Choose Your Database Object and Settings (Tables, Views, or Stored Procedures and Functions) (Don't have "Which version of Entity Framework do you want to use?" because I have only one Entity Framework 6.0 provider so direct skip the selection if my only provider is valid)

9.Finish

恭喜^^

顺便说一句,您可能需要添加.dll文件

By the way, you may need to add the .dll files


  • MySql.Data.dll

  • MySql.Data.Entity.EF6.dll

  • MySql.Web.dll

此文件夹内


C: \\ Program Files \MySQL\MySQL Connector Net 6.8.3 \Assemblies\v4.5
(32bit窗口)

C:\Program Files\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (32bit windows)

C:\Program文件(x86)\MySQL\MySQL连接器Net 6.8.3 \Assemblies\v4.5
(64位窗口)

C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (64bit windows)

作为您进一步EF6功能的项目参考。

as your project reference for further EF6 functions.

这篇关于在Microsoft Visual Studio 2013的WinForms中为MySql(C#)启用实体框架6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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