8
我使用的是VS 2013自帶的標準MVC模板。它有一個整潔的會員供應商,可以輕鬆使用外部登錄(Google,Facebook等)。還有關於如何擴展IdentityUser
模型以添加新的屬性(如出生日期)的教程。MVC/Code First:如何將更多的表添加到相同的數據庫上下文中?
我想補充更多的表(我的應用程序)的已編碼的數據庫上下文,以享受同樣的代碼先遷移功能。我該怎麼做?目前DB上下文定義如下:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
謝謝!有用。我的下一個問題:我如何重寫Seed方法,在每次重新創建數據庫時都可以填充一些示例行? – 2015-02-11 09:10:13
嗨,你可以通過實現自定義數據庫intitializer並覆蓋種子的方法有做到這一點。看看這裏:http://www.entityframeworktutorial.net/code-first/database-initialization-strategy-in-code-first.aspx – Indregaard 2015-02-11 10:48:03