码迷,mamicode.com
首页 > 数据库 > 详细

EF4 Code First和EF6 Code First链接mysql的方法

时间:2014-12-23 17:03:42      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:

1、首先需要下载安装.Net的Mysql驱动

下载地址如下:http://dev.mysql.com/downloads/connector/net/

2、配置Web.Config

EF6:

配置链接字符串

<connectionStrings>
     <add name="sqldata" connectionString="server=地址;Character Set=utf8;User Id=用户名;password=密码;Persist Security Info=True;database=数据库名称" providerName="MySql.Data.MySqlClient" />
</connectionStrings>

配置驱动

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient"></remove><!--预防Machine.config中已经配置了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.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

 配置EF6的驱动

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

 

 

EF4.1:

配置链接字符串

<connectionStrings>
     <add name="sqldata" connectionString="server=地址;Character Set=utf8;User Id=用户名;password=密码;Persist Security Info=True;database=数据库名称" providerName="MySql.Data.MySqlClient" />
</connectionStrings>

配置驱动

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient"></remove><!--预防Machine.config中已经配置了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.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

 

配置完这些就可以使用Mysql了  !



EF4 Code First和EF6 Code First链接mysql的方法

标签:

原文地址:http://www.cnblogs.com/lxiang/p/4180331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!