This is a migrated thread and some comments may be shown as answers.

Parent-Child Associations with WCF RIA Domain Services

2 Answers 109 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vassili King
Top achievements
Rank 1
Vassili King asked on 28 Jul 2010, 06:51 PM
Hello,

I've created a Silverlight WCF RIA solution.  I have DataModels and Domain Services set up. In my Silverlight application, I have a Telerik RadGridView.  The grid works fine if I bind it to the context (some data pulled from a domain service).  However, I cannot figure out a way to create a parent-child association between two contexts.  One of the obstacles on my way is the fact that I'm generating all columns and associations programmatically (the grid is bound to different contexts with differen columns based on different query string values).  Another obstacle is my total lack of knowledge of Telerik Silverlight package.  I've seen demos and whole bunch of articles online, but none seemd to address anything close to what I'm trying to do. 

Below is a more detailed scenario:

Let's say I have two contexts - EmployeeShort (contains only ID, Name and Email) and Employee (contains all the fields of the EmployeeShort context and also a whole bunch of other fields including Location, Phone, Fax, etc.)

I have a simple RadGridView on my Main.xaml page:
 <telerik:RadGridView Name="rgvMainGrid"
                             AutoGenerateColumns="False"
                             IsReadOnly="True"/>

I generate columns and bind data programmatically.

My goal is to have the grid display all records from the EmployeeShort context (which I can easily do), but make every record "extendable" to display a corresponding Employee record with its wide range of employee specific fields (and this is what I can't figure out how to accomplish). 

The GridView demo has a similar scenario - you can see a child record below a parent record displaying more data in it.  However, the data fed into that grid is generated by a parent-child relationship specified in a class.  In my case I have two contexts that can be joined on the ID field (as it is a unique one and shared by both). 

Sample output:

(header)               Name           Email
(parent)                Joe Doe       JD@email.com
(child header)            Name         Email                   Location          Phone  
(child)                        Joe Doe     JD@email.com    Sometown       1(999)123-4567

(another parent)   Joe Smith     JS@email.com
(another parent)   Jane Doe     JaD@email.com
...........


I would really appeciate any ideas.

Thank you!

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 29 Jul 2010, 06:42 AM
Hello,

 It will be better to implement the entire logic in your view-model. In this case the grid will not know anything about the data and you will not have to create different templates, use different events, etc. You can check for example this blog post. You can control also what columns should be auto-generated, columns order and names using Data Annotations attributes. 

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vassili King
Top achievements
Rank 1
answered on 29 Jul 2010, 08:09 PM
Vlad,

Great approach.  It definitely works.  I've been also thinking about a very similar LINQ approach that would look something like this:

void Main()
{
    var children = new List<child>{
      new child{SSN="777-77-7777", id = 1},
      new child{SSN="888-888-888", id = 2}
     };
    
    var parents = new List<parent>{
      new parent{firstName="First", LastName = "Last", id = 1},
      new parent{firstName="First2", LastName = "Last2", id = 2},
      new parent{firstName="First3", LastName = "Last3", id = 3}
     };
    
    var query = from item in parents
     select new { item.firstName, item.LastName, child = (
      from childItem in children
      where item.id == childItem.id
      select new { childItem.SSN, childItem.Desc }
                            ) };
    
    query.Dump();
}

// Define other methods and classes here for now, but in actuality these are defined in the Entity Model
class child
{
    public string Desc;
    public string SSN;
    public int id;
}
   
class parent
{
    public int id;
    public string firstName;
    public string LastName;
}

The code above (if ran in the LINQPad) results in a grid that can be seen in the attached .jpg file.

Thank you for your help!

Best regards,
Vassili.

Tags
GridView
Asked by
Vassili King
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Vassili King
Top achievements
Rank 1
Share this question
or