ef mysql

 App.config

   

<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>
  <connectionStrings>
 
    <add name="ProductContext" connectionString="server=191.168.230.183;Character Set=utf8;User Id=chenshuiyong;password=my_password;Persist Security Info=True;database=test" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  
  
  
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
      <!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
    </providers>
    <contexts>
      <context type="ConsoleApplication1.ProductContext, ConsoleApplication1">
        <databaseInitializer type="ConsoleApplication1.ProductInitializer, ConsoleApplication1"/>
      </context>
    </contexts>
  </entityFramework>




  <system.data>

    <DbProviderFactories>
      <!-- 不设置这里会提示找不到提供程序-->
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/>
    </DbProviderFactories>
  </system.data>
  
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

安装 EntityFramework
1  Install-Package EntityFramework -pre
2  
3  Install-Package MySQL.Data.Web -Version 6.5.4
4  Install-Package MySQL.Data.Entities -Version 6.5.4
5  Install-Package MySql.Data.Entity.EF6
View Code

  代码迁移

  

 Enable-Migrations -ContextTypeName MvcMovie.Models.MovieDbContext

Add-Migration AddBlogUrl
 Update-Database –Verbose

  

posted @ 2014-03-31 11:44  @索卡  阅读(1000)  评论(0编辑  收藏  举报