1.
Enable-Migrations
2.
Add-Migration TagName
3.
Update-Database
注意,每次更改cs后,注意Build,再运行命令。
MySql参考:
摘要:
1. 添加nuget引用:
<package id="MySql.Data" version="6.7.5" targetFramework="net45" />
<package id="MySql.Data.Entity" version="6.7.5" targetFramework="net45" />
Web.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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=FirstMvc4App;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\FirstMvc4App.mdf" providerName="System.Data.SqlClient" />-->
<add name="MySqlConnection" connectionString="Datasource=localhost;Database=FirstMvc4App;uid=root;pwd=mypassword;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
...
<entityFramework>
<!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />-->
<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</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.7.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
</configuration>