如果您创建一个DomainService,公开一个实体,您可以访问聚合实体吗?

发布于 2024-10-07 08:33:47 字数 496 浏览 0 评论 0原文

假设您创建了一个 RIA DomainService,并在其中包含一个 Person(如下所示)实体,您可以访问该对象上的聚合实体吗?

例如,如果我有这样的实体(请记住,这是一个幼稚的表示,它们是通过 EF4 设计器建模的):

public class Person
{
    string FirstName { get; set; }
    PhoneNumber { get; set; }
}

public class PhoneNumber
{
    public string AreaCode { get; set; }
    public string Trunk { get; set; }
    public string Number { get; set; }
}

如果我在创建 PeopleDomainService 时包含 Person,客户端是否可以访问PhoneNumber 就可以了(并修改它)?

Say you create an RIA DomainService and you include a Person (shown below) entity in it, can you access aggregate entities on that object?

For instance, if I have entities like so (keep in mind that this is a naive representation, they are modeled via the EF4 designer):

public class Person
{
    string FirstName { get; set; }
    PhoneNumber { get; set; }
}

public class PhoneNumber
{
    public string AreaCode { get; set; }
    public string Trunk { get; set; }
    public string Number { get; set; }
}

If I include Person when creating the PeopleDomainService, can the client access the PhoneNumber on it (and modify it)?

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

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

发布评论

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

评论(2

你怎么敢 2024-10-14 08:33:47

您可以使用 [Include] 属性来修饰 Person 对象的 PhoneNumber 属性。当您获取 Person 对象时,还请记住在 LINQ 查询中包含 include 语句。

You can decorate the PhoneNumber attribute of the Person object with the [Include] attribute. Remember also to include an include statement in your LINQ query when you get a Person object.

无尽的现实 2024-10-14 08:33:47

是的,您可以引入相关实体。

在 PeopleDomainService.metadata.cs 文件中,查找 PersonMetadata 类。在 PhoneNumbers 属性上,添加“Include”属性:

[Include]:
public EntityCollection<PhoneNumber> PhoneNumbers { get; set; }

在 PeopleDomainService.cs 中,查找 GetPersons 函数并修改它以包含 PhoneNumbers:

public IQueryable<Person> GetPersons()
{
    return this.ObjectContext.Persons.Include("PhoneNumbers");
}

您可以在 MSDN > 上找到更多详细信息。 演练:了解 RIA 服务 > >显示相关数据

Yes, you can bring in related entities.

In the PeopleDomainService.metadata.cs file, look for the PersonMetadata class. On the PhoneNumbers property, add the "Include" attribute:

[Include]:
public EntityCollection<PhoneNumber> PhoneNumbers { get; set; }

In the PeopleDomainService.cs, look for the GetPersons function and modify it to include the PhoneNumbers:

public IQueryable<Person> GetPersons()
{
    return this.ObjectContext.Persons.Include("PhoneNumbers");
}

You can find more details on MSDN > Walkthrough: Taking a Tour of RIA Services > Displaying Related Data

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文