我有三个模型,如下面
第一
function setImg() {
var img1 = document.getElementById('image1'),
img2 = document.getElementById('image2'),
offtop = ((img1.offsetHeight/2)-(img2.offsetHeight/2)),
offleft = ((img1.offsetWidth/2)-(img2.offsetWidth/2));
img2.style.top = offtop + "px";
img2.style.left = offleft + "px";
}
window.load = setImg();
window.addEventListener('resize',setImg);
第二
public partial class provider_preapproval
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long preapproval_id { get; set; }
.......
public DateTime? sync_time { get; set; }
public IList<provider_diagnosis_dtls> provider_diagnosis_dtls { get; set; }
public IList<provider_service_dtls> provider_service_dtls { get; set; }
}
第三
public partial class provider_diagnosis_dtls
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long diagnosis_id { get; set; }
public long preapproval_id { get; set; }
..........................
}
其中第一个模型中的public partial class provider_service_dtls
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long service_id { get; set; }
public long preapproval_id { get; set; }
..................
}
在保存到db时用作两者的外键。它成功保存了详细信息。
但是,当我调用模型显示preapproval_id
和provider_diagnosis_dtls
时,它将显示如下:(
我的控制器
provider_service_dtls
我在做什么是错的。请帮忙。
答案 0 :(得分:0)
列表为空,因为在表示数据库记录的类型之间没有指定关系。为了做到这一点,您需要指定导航属性并使用Text
和ForeignKeyAttribute
的正确组合来装饰它们:
InversePropertyAttribute
请注意,我将导航属性标记为public partial class provider_preapproval
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long preapproval_id { get; set; }
[InverseProperty("preapproval")]
public virtual IList<provider_diagnosis_dtls> provider_diagnosis_dtls { get; set; }
[InverseProperty("preapproval")]
public virtual IList<provider_service_dtls> provider_service_dtls { get; set; }
//...
}
public partial class provider_diagnosis_dtls
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long diagnosis_id { get; set; }
public long preapproval_id { get; set; }
[ForeignKey("preapproval_id"), InverseProperty("provider_diagnosis_dtls ")]
public virtual provider_preapproval preapproval { get; set; }
//...
}
public partial class provider_service_dtls
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long service_id { get; set; }
public long preapproval_id { get; set; }
[ForeignKey("preapproval_id"), InverseProperty("provider_service_dtls")]
public virtual provider_preapproval preapproval { get; set; }
//...
}
,以便它们是延迟加载的(在访问属性时从数据库加载,而不是在加载&#34;所有者&#34;对象 - 它的时候加载有点按需加载政策。