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

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

问题描述

昨天,我知道,实体框架是访问使用数据集或DataReader的数据库旁边的另一种方法,然后我试图让实体框架6作品在2013年MVS我的MySQL数据库服务器

我打开与.NET框架4.5.1一个WinForms。 (所以我只有App.config中,但项目中没有应用程序/ Web配置)
安装后,我的mysql-installer-community-5.7.3.0-m13.msi

通过

安装的EntityFramework包

  

工具菜单 - >库包管理器 - >管理的NuGet包的
  解决方案... - >在线 - >(搜索)的EntityFramework(提防版
  这个包的,它应该是6.0.2版本,如果没有然后单击
  更新 - >的EntityFramework更新)


当我试图通过

添加ADO.NET实体数据模型

  

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


则生成实体连接字符串 - >中App.Config中勾选实体连接设置另存为 - >下一步> - >

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


  

你的项目引用最新版本的实体框架;
  然而,实体框架的数据库提供与此兼容
  版本不能为您的数据连接被发现。退出该向导,
  安装兼容的供应商,前rebuid项目
  执行这个动作。


如何解决此问题?

顺便说一句,如果你的NuGet包安装实体框架5版本,那么你可能会选择实体框架5.0在这里,你可能成功使用实体框架5而不是第6版。


解决方案

首先,我们的甚至不需要以安装MySQL-installer-的社区 - 5.7.3.0-m13.msi。


  1. 安装最新的<一个href=\"https://dev.mysql.com/downloads/windows/visualstudio/1.2.html\">mysql-visualstudio-plugin

  2. 安装最新的使用mysql-connector-网

  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


  

的EntityFramework


  
  

Mysql.Data
  
  

Mysql.Data.Entities


  
  

Mysql.Web


5。如果你有标记的EntityFramework App.config中,请评论并标记启动后在App.config中插入新的标签的EntityFramework

 &LT;&的EntityFramework GT;
    &LT; defaultConnectionFactory TYPE =MySql.Data.Entity.MySqlConnectionFactory,MySql.Data.Entity.EF6/&GT;
    &LT;供应商&GT;
      &LT;供应商invariantName =MySql.Data.MySqlClientTYPE =MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity.EF6/&GT;
    &LT; /供应商&GT;
  &LT; /&的EntityFramework GT;

6.增加 ADO.NET实体数据模型(如问题提到的)

7.After产生的实体连接字符串(如问题提到的),并在App.Config中蜱实体连接设置另存为然后单击下一步

8的选择您的数据库对象和设置的(表,视图,或存储过程和函数)(不要有你想要哪个实体框架的版本使用?因为我有只有一个实体框架6.0提供这么直接的跳过如果我的唯一供应商是有效的选择)

9.Finish

恭喜^^

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


  • MySql.Data.dll

  • MySql.Data.Entity.EF6.dll

  • MySql.Web.dll

该文件夹中。


  

C:\\ Program Files文件\\的MySQL \\ MySQL的连接器6.8.3净\\组件\\ V4.5
  (32位视窗)


  
  

C:\\ Program Files文件(x86)的\\ MySQL的\\ MySQL的连接器6.8.3净\\组件\\ V4.5
  (64位视窗)


为进一步E​​F6功能项目的参考。

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.

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

install EntityFramework package via

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)

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

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

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

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".

How to solve this?

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.

解决方案

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

  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

Mysql.Data

Mysql.Data.Entities

Mysql.Web

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.Add ADO.NET Entity Data Model (as mentioned in question)

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.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

Congratulations ^^

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

  • MySql.Data.dll
  • MySql.Data.Entity.EF6.dll
  • MySql.Web.dll

inside this folder

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

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

as your project reference for further EF6 functions.

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

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