Mysql 6.7.7 + EntityFramework 5.0 Code First 不能 Update-Database 問題的解決

來源:互聯網
上載者:User

標籤:

1、修改 Migrations/Configuration.cs 檔案
 1 namespace DataModel.Migrations 2 { 3     using System; 4     using System.Data.Entity; 5     using System.Data.Entity.Migrations; 6     using System.Linq; 7  8     internal sealed class Configuration : DbMigrationsConfiguration<DataModel.SpaceDataContext> 9     {10         public Configuration()11         {12             AutomaticMigrationsEnabled = true;13 14             AutomaticMigrationDataLossAllowed = true;15             16             SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());    // This will add our MySQLClient as SQL Generator  17         }18 19         protected override void Seed(DataModel.SpaceDataContext context)20         {21             //  This method will be called after migrating to the latest version.22 23             //  You can use the DbSet<T>.AddOrUpdate() helper extension method 24             //  to avoid creating duplicate seed data. E.g.25             //26             //    context.People.AddOrUpdate(27             //      p => p.FullName,28             //      new Person { FullName = "Andrew Peters" },29             //      new Person { FullName = "Brice Lambson" },30             //      new Person { FullName = "Rowan Miller" }31             //    );32             //33         }34     }35 }

 

2、修改 App.config 檔案 entityFramework 節點
1   <entityFramework>2     <defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />3     <contexts>4       <context type="DataModel.SpaceDataContext,DataModel">5         <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[DataModel.SpaceDataContext,DataModel], [DataModel.Migrations.Configuration,DataModel]], EntityFramework" />6       </context>7     </contexts>8   </entityFramework>

 

3、完事!! 注意紅色高亮處哦

  

Mysql 6.7.7 + EntityFramework 5.0 Code First 不能 Update-Database 問題的解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.