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
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.