【发布时间】:2014-04-16 01:00:22
【问题描述】:
我在为我的数据库播种和给外键赋值时遇到问题。
这是我的 UserPains 模型:
public partial class UserPain
{
public int Id { get; set; }
public int ScoredBy { get; set; }
public DateTime LastUpdated { get; set; }
public virtual Defect Defects { get; set; }
}
这是我的缺陷模型:
public partial class Defect
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
所以当我播种时:
new UserPain { ScoredBy = 1, LastUpdated = DateTime.Now }
UserPain 表中标记为 Defects_Id 的值为空。如何将 Defects_Id 的值分配给缺陷表中现有缺陷的 id?
【问题讨论】:
标签: c# ef-code-first foreign-keys entity-framework-migrations