Tep*_*epu 10 entity-framework ef-code-first ef-migrations
我正在使用EF5和MVC4.问题是我的数据库中有大量数据,我已经从旧数据库中导入了数据.我想在模型更改时加载种子数据.我的问题是如何播放已存在于我的数据库中的大量数据?
internal sealed class Configuration : MigrationsConfiguration<VoiceLab.Models.EFDataContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(VoiceLab.Models.EFDataContext context)
{
//what to do here to seed thousands or records that are already in db
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
Tep*_*epu 17
以下是通过在种子方法中提供.sql文件来播种批量数据的方法.
public class AppContextInitializer : CreateDatabaseIfNotExists<AppContext>
{
protected override void Seed(AppContext context)
{
var sqlFiles = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.sql").OrderBy(x => x);
foreach (string file in sqlFiles)
{
context.Database.ExecuteSqlCommand(File.ReadAllText(file));
}
base.Seed(context);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3286 次 |
| 最近记录: |