国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

EF6+MySql code first

2019-11-11 07:37:24
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1  安裝必要的開(kāi)發(fā)包

     MySQL For Visual Studio 和  Connector/NET

2  Nuget安裝MySQL庫(kù): Install-Package MySql.Data.Entity -Version 6.9.8

    安裝完畢后,項(xiàng)目中的引用自動(dòng)添加EntityFramework、MySql.Data、MySql.data.Entity.EF6 三個(gè)程序集

3 編輯app.config配置文件

<?xml version="1.0" encoding="utf-8"?><configuration>  <configSections>    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />  </configSections>  <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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />    </DbProviderFactories>  </system.data>  <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>

  <connectionStrings>    <add name="MyContext" connectionString="Data Source=120.77.46.150; Initial Catalog=beikeda_da;user id=keedb;passWord=1234;" providerName="MySql.Data.MySqlClient"/>  </connectionStrings></configuration>

 

4  修改 myDbContext類(lèi)文件,增加屬性 [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]

5 數(shù)據(jù)庫(kù)遷移:參考

            Database.SetInitializer(new MigrateDatabaseToLatestVersion<makerdb, Configuration<makerdb>>());            Database.SetInitializer(new CreateDatabaseIfNotExists<makerdb>());            Database.SetInitializer<makerdb>(null);

   internal sealed class Configuration<TContext> : DbMigrationsConfiguration<TContext> where TContext : DbContext    {        public Configuration()        {            AutomaticMigrationsEnabled = true  ;            AutomaticMigrationDataLossAllowed = true;            // register mysql code generator            SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());

        }    }


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 廉江市| 海林市| 江津市| 资溪县| 神农架林区| 响水县| 平罗县| 彰武县| 习水县| 岳池县| 汉寿县| 蓬莱市| 城口县| 华阴市| 隆尧县| 汤原县| 深州市| 绍兴市| 旌德县| 建水县| 靖州| 墨竹工卡县| 凤城市| 金秀| 甘孜县| 山东| 鹤山市| 云安县| 高邮市| 黄冈市| 阜康市| 淅川县| 南部县| 平阴县| 富蕴县| 青海省| 绩溪县| 英吉沙县| 都昌县| 外汇| 寿宁县|