如果您创建一个DomainService,公开一个实体,您可以访问聚合实体吗?
假设您创建了一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 [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.
是的,您可以引入相关实体。
在 PeopleDomainService.metadata.cs 文件中,查找 PersonMetadata 类。在 PhoneNumbers 属性上,添加“Include”属性:
在 PeopleDomainService.cs 中,查找 GetPersons 函数并修改它以包含 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:
In the PeopleDomainService.cs, look for the GetPersons function and modify it to include the PhoneNumbers:
You can find more details on MSDN > Walkthrough: Taking a Tour of RIA Services > Displaying Related Data