Created
December 12, 2013 07:27
-
-
Save bernos/7924367 to your computer and use it in GitHub Desktop.
MySql with entity framework 5.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MySql.Data.Entity; | |
namespace MyProject.Migrations | |
{ | |
using System; | |
using System.Data.Entity; | |
using System.Data.Entity.Migrations; | |
using System.Linq; | |
internal sealed class Configuration : DbMigrationsConfiguration<MySqlEntityFrameworkTest.ChinookContext> | |
{ | |
public Configuration() | |
{ | |
AutomaticMigrationsEnabled = false; | |
// IMPORTANT! We need to specify our code generator and sql generator, or we'll | |
// get unusable migration classes and sql scripts | |
CodeGenerator = new MySqlMigrationCodeGenerator(); | |
SetSqlGenerator("MySql.Data.MySqlClient", new MySqlMigrationSqlGenerator()); | |
} | |
protected override void Seed(MySqlEntityFrameworkTest.ChinookContext 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" } | |
// ); | |
// | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We're assuming MySql.Data.Entities v6.7.4 for this guide. | |
First install MySql.Data.Entities: | |
Install-Package MySql.Data.Entities | |
Then install EF version 5.0.0: | |
Install-Package EntityFramework -Version 5.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<system.data> | |
<DbProviderFactories> | |
<remove invariant="MySql.Data.MySqlClient"/> | |
<add name="MySQL Data Provider" | |
invariant="MySql.Data.MySqlClient" | |
description="Data Provider for MySQL" | |
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" /> | |
</DbProviderFactories> | |
</system.data> | |
<connectionStrings> | |
<add name="DataContext" | |
connectionString="server=localhost;database=MyDatabase;User Id=root;Password=" | |
providerName="MySql.Data.MySqlClient" /> | |
</connectionStrings> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment