开发者

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

Say you create an RIA DomainService and you include a Person (shown below) e开发者_StackOverflowntity 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)?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜