If you create a DomainService, exposing an entity, can you access aggregate entities?

折月煮酒 提交于 2019-12-06 06:28:57

问题


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)?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4393104/if-you-create-a-domainservice-exposing-an-entity-can-you-access-aggregate-enti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!