namespace Healthcare
{
public class Doc
{
public int DocId { get; set; }
public string DocName { get; set; }
public string Street { get; set; }
public int Number { get; set; }
public string Zip { get; set; }
public string Place { get; set; }
public List<DocContract> DocContract { get; set; }
}
public class DocContract
{
public int DocId { get; set; }
public string Date { get; set; }
public Doc Doc { get; set; }
}
}
每当我尝试启用迁移时,我都会收到以下错误消息:
Healthcare.DocContract::EntityType'DocContract'没有定义键。 定义此EntityType的密钥。
如何解决此错误?基本上每个文档都有一份合同
答案 0 :(得分:2)
此处显示一对一关系,其中DocContract
是依赖的:
public class Doc
{
public int DocId { get; set; }
public string DocName { get; set; }
public string Street { get; set; }
public int Number { get; set; }
public string Zip { get; set; }
public string Place { get; set; }
public virtual DocContract DocContract { get; set; }
}
public class DocContract
{
[Key]
[ForeignKey("Doc")]
public int DocId { get; set; }
public string Date { get; set; }
public virtual Doc Doc { get; set; }
}