Mar
8
If you have a table with related tables then you can get the child entries by editing the DomainService and the metadata:
Add the include attribute ([Include()]) to the property containing the child table reference and use the DataLoadOptions to specify the child tables to include in the query result view.
In this case a Task table contains a reference to a Project table and the Project table contains a reference to the Customer table:
The domainservice class TTSDomainService
// TODO: Consider // 1. Adding parameters to this method and constraining returned results, and/or // 2. Adding query methods taking different parameters. public IQueryable<Task> GetTasks() { // Define the child entries to get DataLoadOptions options = new DataLoadOptions(); options.LoadWith<Task>(t => t.Project); options.LoadWith<Project>(p => p.Customer); this.DataContext.LoadOptions = options; // Get the tasks ordered by customer, project, task return from t in this.DataContext.Tasks orderby t.Project.Customer.Name, t.Project.Name, t.Name select t; }
The domainservice meta data class: TTSDomainService.metadata.cs
// The MetadataTypeAttribute identifies TaskMetadata as the class // that carries additional metadata for the Task class. [MetadataTypeAttribute(typeof(Task.TaskMetadata))] public partial class Task { // This class allows you to attach custom attributes to properties // of the Task class. // // For example, the following marks the Xyz property as a // required field and specifies the format for valid values: // [Required] // [RegularExpression("[A-Z][A-Za-z0-9]*")] // [StringLength(32)] // public string Xyz; internal sealed class TaskMetadata { // Metadata classes are not meant to be instantiated. private TaskMetadata() { } public Nullable<int> CategoryAbbrID; public int CategoryID; public Nullable<decimal> EstDuration; public Nullable<int> HourType; public string Name; [Include()] public Project Project; public int ProjectID; public EntitySet<TaskTimeSpan> TaskTimeSpans; } }
See:
Tags: Silverlight, WCF RIA Services


This is great, thanks, but how do you update data in the child tables?
Basically, with your method, I am able to load realted/child data to show in a grid or so, but how can I now make updates into those child tables?
Thanks
–tolga
Great! I was banging my head on the wall because all samples on the net use .Include()… Thanks!