• EF CodeFirst使用MySql


    1、引入包

    EntityFramework
    MySql.Data.Entity
    2、配置文件 web.config
      <connectionStrings>
        <add name="IdeaSiteContext" connectionString="Data Source=localhost;port=3306;Initial Catalog=ideasite_db;user id=root;password=cw123456;" providerName="MySql.Data.MySqlClient" />
      </connectionStrings>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <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.EF5, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
          </provider>
        </providers>
      </entityFramework>
      <system.data>
        <DbProviderFactories>
          <remove invariant="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.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
        </DbProviderFactories>
      </system.data>

    3、注意事项

    如果是ef 5.0则需要去掉配置文件中的  providers 节点
    mysql中不支持 timestamp 数据类型
     
  • 相关阅读:
    ubuntu 12.04 配置双屏幕教程
    window打开服务的dos命令
    ffmpeg 视频转换和截图 方法
    pycharm
    Django mptt介绍以及使用
    浅谈Python Web框架
    activity 的属性android:taskAffinity和android:allowTaskReparenting
    android TranslateAnimation动画详解
    Android中Activity启动模式详解
    android:descendantFocusability用法简析
  • 原文地址:https://www.cnblogs.com/ideacore/p/6289514.html
Copyright © 2020-2023  润新知