我有我想要的数据库设置,只是对现有表进行调整并偶尔添加新表,并且在初始播种后已将实时数据添加到表中。因此,如果我想添加一个新表并只为该表提供种子,同时将其他表中的数据保持原样,这可能吗?我不想删除现有表或丢失现有数据,我只想添加一个新表并在创建它的同时用数据播种它。
问问题
140 次
1 回答
0
I'd love to know if there's a better way of doing this.
When I add a model, then in my Migrations/Congiruation.cs file I add the appropriate seeding values and basically just comment out the rest. ie:
var Locations = new List<Location>
{
new Location { Suburb="Sydney", Postcode = "2000", State = "NSW"}
};
Locations.ForEach(s => context.Locations.Add(s));
context.SaveChanges();
for a new Location model. Unless you have set drop database if model changes in your initialiser, then running update-database in your package manager console will not affect any of your other tables or data.
于 2013-09-22T22:37:46.030 回答