我正在使用帶有ASP.NET MVC5項目的EF Code First Migration。我想用約5000條記錄爲數據庫播種。 asp.net網站和博客上的例子在配置方法中都有種子功能。EF遷移使用大型數據集播種
internal sealed class Configuration : DbMigrationsConfiguration<foo.ApplicationDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
MigrationsDirectory = @"Migrations\ApplicationDbContext";
}
protected override void Seed(foo.ApplicationDbContext context)
{
SeedProducts(context);
SeedFoods(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" }
// );
//
}
}
在使用EF遷移時種子大數據集有哪些選項?
目前配置文件長度超過5000行,管理方式不同。
我寧願將它們存儲在另一個數據庫或Excel電子表格中,然後使用種子函數導入它們。我不知道如何在Seed方法中從外部源導入數據。
我也試圖打破了數據集分成幾個文件,但是當我嘗試調用函數
SeedProducts(context);
SeedFoods(context);
外的配置類,我收到了生成錯誤的:「這個名字並不存在於當前情境「。 (我不知道這是什麼意思?
爲什麼不最初種子數據庫(因爲你已經有一個工作種子功能),然後保存一個備份(或備份腳本),然後運行(新)種子函數內該腳本?您可以儘快從Web API或搜索引擎獲取數據庫,因爲您可以「手動」。 – jpaugh 2014-09-06 02:49:18