【问题标题】:Get EntityCollection from within another entity从另一个实体中获取 EntityCollection
【发布时间】:2011-03-24 18:25:10
【问题描述】:

我有一个包含 entityB 的 EntityCollection 的 entityA。 我在定义 entityB 的行上使用 [include] 装饰更新了 EntityA 的元数据,如下所示:

[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 的计数为零。 我在这里错过了什么!

最好的问候

【问题讨论】:

    标签: silverlight-4.0 wcf-ria-services


    【解决方案1】:

    您需要使用AssociationAttribute 定义summerydaily 之间的关联。

    [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)]
    

    【讨论】:

    • 你好 Ed,如果关联需要多个键,例如summery_field1、summary_field2、summary_field3 与 parent_summary_filed1、parent_summary_filed2、parent_summary_filed3 怎么办??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多