如何在不创建新条目的情况下使用数据库生成的ID列对数据库进行种子设定?例如:
public class Stuff
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
}
和种子方法:
var project1Id = new Guid("8853EDF3-BA20-43F8-B8D6-06984116CF8C");
context.Projects.AddOrUpdate(p => p.Id, new Project
{
Id = project1Id,
Statuses = new List<Status>
{
new Status { Comments = "Comment 1", LastUpdated = DateTime.Now, Type = StatusType.Internal },
new Status { Comments = "Comment 2", LastUpdated = DateTime.Now, Type = StatusType.Business }
}
});
问题在于它忽略了我指定的GUID,而是每次运行update-database
时自动生成一个新GUID。我正在使用VS2012和EF5。