如果创建一个DomainService,暴露一个实体,你可以访问聚合实体吗? [英] If you create a DomainService, exposing an entity, can you access aggregate entities?
问题描述
假设您创建了一个RIA DomainService,并在其中包含一个 Person
(如下所示)实体,您可以访问该对象上的聚合实体吗?
public class Person
{
string FirstName {get;组; }
PhoneNumber {get;组; }
}
public class PhoneNumber
{
public string AreaCode {get;组; }
public string Trunk {get;组; }
public string Number {get;组;
}
如果我包含 Person
在创建PeopleDomainService时,客户端是否可以访问 PhoneNumber
(并修改它)?
是的,您可以引入相关实体。
在PeopleDomainService.metadata.cs文件中,查找PersonMetadata类。在PhoneNumbers属性上,添加Include属性:
[Include]:
public EntityCollection< PhoneNumber> PhoneNumbers {get;组;
在PeopleDomainService.cs中,查找GetPersons函数并修改它以包含PhoneNumbers:
public IQueryable< Person> GetPersons()
{
return this.ObjectContext.Persons.Include(PhoneNumbers);
}
您可以在MSDN上找到更多详细信息> 演练:参观RIA服务>显示相关数据
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)?
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
这篇关于如果创建一个DomainService,暴露一个实体,你可以访问聚合实体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!