1、修改 Migrations/Configuration.cs 文件
namespace DataModel.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq; internal sealed class Configuration : DbMigrationsConfiguration<DataModel.SpaceDataContext>
{
public Configuration()
{
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
} protected override void Seed(DataModel.SpaceDataContext context)
{
// This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
}
2、修改 App.config 文件 entityFramework 节点
<entityFramework>
<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
<contexts>
<context type="DataModel.SpaceDataContext,DataModel">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[DataModel.SpaceDataContext,DataModel], [DataModel.Migrations.Configuration,DataModel]], EntityFramework" />
</context>
</contexts>
</entityFramework>
3、完事!! 注意红色高亮处哦