我有一个entityA,它包含entityB的EntityCollection。 我使用[include]装饰在EntityA的metdata上更新了定义entityB的行,如下所示:
[Include]
public EntityCollection<daily> daily { get; set; }
在我的domainservice类中,我有一个函数来检索entityA,如下所示:
var summary =
(from S in ObjectContext.summery.Include("daily")
where S.daily_number == daily_number
&& S.month_number == month_number
&& S.period_id == period_id
select S).FirstOrDefault();
return summary;
从客户端我总是得到entityB的零。 我在这里错过了什么!!
祝你好运
答案 0 :(得分:0)
您需要使用AssociationAttribute定义summery
和daily
之间的关联。
[Include]
[Association("SomeUniqueName", "summery_id", "parent_summery_id", IsForeignKey = false)]
public EntityCollection<daily> daily { get; set; }
我对你的课程进行了以下假设
public class summery
{
...
public int? summery_id { get; set; }
...
}
public class daily
{
...
// Foreign key to the parent summery
public int parent_summery_id { get; set; }
...
}
修改强>
在回应Waleed的评论时,复合外键关联看起来像
[Association("SomeUniqueName",
"summery_field1, summary_field2, summary_field3",
"parent_summary_filed1, parent_summary_filed2, parent_summary_filed3",
IsForeignKey = false)]