【发布时间】:2017-03-27 14:02:26
【问题描述】:
我已经使用代码优先迁移为数据库播种,但是当我在 index.html 中查看播种数据时,我注意到数据被复制了。
这是我植入数据时的配置文件:
内部密封类配置:DbMigrationsConfiguration { 公共配置() { AutomaticMigrationsEnabled = 假; }
protected override void Seed(OnlineBookStore.Models.OnlineBookStoreDB context)
{
var books = new System.Collections.Generic.List<Book>
{
new Book {
BookStatus = new BookStatus { Status = "New" },
Genre = new Genre { Name = "Thriller" },
Author = new Author { Name = "Paula Hawkins" },
Title = "The Girl On The Train",
Description = "Rachel catches the same commuter train morning. ",
ISBN = 0552779776,
},
new Book
{
BookStatus = new BookStatus { Status = "Best Seller" },
Genre = new Genre { Name = "Childrens" },
Author = new Author { Name = "Roald Dahl" },
Title = "The Witches",
Description = "Beware. Real witches dress in ordinary clothes",
ISBN = 0141365471,
},
},
};
books.ForEach(s =>context.Books.AddOrUpdate(p => new { p.ISBN, p.Title } ));
context.SaveChanges();
}
}
}
我真的不确定我是不是错了,花了好几天的时间! 真的很感谢任何人的帮助!谢谢!
【问题讨论】:
标签: asp.net-mvc entity-framework-migrations