????????????????????????????Mysql??????Щ????????sql server???mysql……
???????????Mysql???????????utf8????????????????????????????????????????utf8??????????????ef????????????????????????????
??????????????????mysql??EF??
???????NuGet?????????????EntityFramework6.1.3??MySql.Data.Entity6.9.8
???????????nuget???????м???
????Install-Package MySql.Data.Entity
????????????????
????1????? User ?????
?????????????????γ?????????????????Specified key was too long;max key length is 767 bytes ????????????string ??????????mysql ?е????longtext????mysql ???????767 bytes.
????public class User
????{
????public int Id { get; set; }
????[StringLength(30)]
????public string UserName { get; set; }
????[MaxLength(30)]
????public string PassWord { get; set; }
????}
????2????? MyContext ??
???????????MySql??????? [DbConfigurationType(typeof(MySqlEFConfiguration))]
????[DbConfigurationType(typeof(MySqlEFConfiguration))]
????public class MyContext : DbContext
????{
????public MyContext()
????: base("name=MyContext")//web.config??connectionstring??????
????{
????}
????public DbSet<User> Users { get; set; }
????}
????3??д????????
????Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyContext>());
????var context = new MyContext();
????//????????
????context.Users.Add(new User { UserName = "EF6MySQL" });
????context.SaveChanges();
????????????Web.config
??????<connectionStrings>?м??????′???
????<add name="MyContext" connectionString="Data Source=localhost;port=3306;Initial Catalog=MySQL_EF;user id=root;password=root;" providerName="MySql.Data.MySqlClient" />
??????????web.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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory ?? EntityFramework" />
<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.EF6?? Version=6.9.8.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.9.8.0?? Culture=neutral?? PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MyContext" connectionString="Data Source=localhost;port=3306;Initial Catalog=MySQL_EF;user id=root;password=root;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
</configuration>
?????????г??????????????????