从另一个实体中获取 EntityCollection

发布于 2024-10-27 00:06:17 字数 590 浏览 0 评论 0原文

我有一个实体 A,其中包含实体 B 的 EntityCollection。 我用定义实体B的行上的[include]装饰更新了实体A的元数据,如下所示:

[Include]
public EntityCollection<daily> daily { get; set; }

在我的域服务类中,我有一个检索实体A的函数,如下所示:

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;

从客户端我总是得到实体B的计数为零。 我在这里缺少什么!!

此致

I have an entityA that contains a EntityCollection of entityB.
I updated the metdata for EntityA with the [include] decoration over the line defining the entityB as follows:

[Include]
public EntityCollection<daily> daily { get; set; }

in my domainservice class I have a function to retrieve entityA as follows:

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;

From the Client I always get count Zero of entityB.
What am I missing here !!

Best regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2024-11-03 00:06:17

您需要使用 AssociationAttribute

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

You'll need to define the association between summery and daily with the AssociationAttribute.

[Include]
[Association("SomeUniqueName", "summery_id", "parent_summery_id", IsForeignKey = false)]
public EntityCollection<daily> daily { get; set; }

I am making the following assumptions about your classes

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; }
...
}

Edit:

In response to Waleed's comment, a composite foreign key association could look like

[Association("SomeUniqueName",
             "summery_field1, summary_field2, summary_field3",
             "parent_summary_filed1, parent_summary_filed2, parent_summary_filed3",
             IsForeignKey = false)]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文