我试图与我的模特建立一对一的关系。但是我得到了以下错误:“关系'DetayAcıklama_UrunBilgi'中的角色'DetayAcıklama_UrunBilgi_Target'中的多重性无效。由于Dependent Role属性不是关键属性,因此Dependent Role的多重性的上限必须为'*' 。“
我的模型如下:
public class Urun
{
[Key]
public int UrunID { get; set; }
[Required]
public string UrunKodu { get; set; }
[Required]
public decimal Fiyat { get; set; }
[ForeignKey("DetayBilgi")]
public int DetayAcıklamaID { get; set; }
public DetayAcıklama DetayBilgi { get; set; }
}
public class DetayAcıklama
{
[Key]
public int DetayAcıklamaID { get; set; }
[Display(Name = "Açıklama")]
public string AcıklamaTxt { get; set; }
public decimal Fiyat { get; set; }
[Required, ForeignKey("UrunBilgi")]
public int UrunID { get; set; }
public Urun UrunBilgi { get; set; }
}
我错过了什么?提前致谢
答案 0 :(得分:0)
您当前的实现没有说明哪个表依赖于哪个表..为此指定主键列作为外键:
[Key, ForeignKey("UrunBilgi")]
public int DetayAcıklamaID { get; set; }