# .NET and More > Silverlight >  Parent Child

## jaykappy

I have a project that has two tables in it.  Businesses and Address.  One to many...Mutiple Suit info in the address table...regardless thats not the issue here...what I am trying to do is return all the businesses and as the user selects one of the businesses in the main grid it selects all the related recrods in the address table and displays them on another grid.

I have to main grid upa dn running and on change of selection I can pop a message box up with a particular field value from the Business table...so far so good...
But I am now trying to grab that selceted record and select all the related records in the other table and populate another grid...This is what I am runnign into issues....

I am bombing out on this line:
Dim loadOp = Me._OrganizationContext.Load(query)

I get this ERROR:
Data type(s) of the type parameter(s) in method 'Public Function Load(Of TEntity As System.ServiceModel.DomainServices.Client.Entity)(query As System.ServiceModel.DomainServices.Client.EntityQuery(Of TEntity)) As System.ServiceModel.DomainServices.Client.LoadOperation(Of TEntity)' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.


I also tried this

Dim loadOp As LoadOperation(Of Address) = context.Load(context.query())


Any thoughts?


DOMAIN SERVICE


```
    Public Function GetCoreBusinesses2() As IQueryable(Of CoreBusiness)
        Return Me.ObjectContext.CoreBusinesses.OrderBy(Function(e) e.ID)
    End Function

    Public Function GetAddresses() As IQueryable(Of Address)
        Return Me.ObjectContext.Addresses.OrderBy(Function(e) e.ID)
    End Function
```

VB


```
        Dim _selectedItem = TryCast(dataGrid1.SelectedItem, CoreBusiness)
        Dim Test As String = _selectedItem.BusinessName
        MessageBox.Show(Test)

        Dim query = _OrganizationContext.Addresses().Where(Function(child) child.CB_ID = _selectedItem.ID)

        Dim loadOp = Me._OrganizationContext.Load(query)
        dataGrid2.ItemsSource = loadOp.Entities
```

----------


## jaykappy

This is where I am right now...I think I have straightened a few things out...especially the query itself...now pointing to the Domain Service and specified query within...There are not any coding errors beign returned...jsut when I run the code itself..



```
        Dim _selectedItem = TryCast(dataGrid1.SelectedItem, CoreBusiness)
        Dim _query = _OrganizationContext.GetAddressesQuery().Where(Function(child) child.CB_ID = _selectedItem.ID)
        Dim loadOp = Me._OrganizationContext.Load(_query)
        timeEntryDataGrid.ItemsSource = loadOp.Entities
```

When I run this code I am getting an error...Its pointing to "(_query)" on the third line

Error: Expression of type 'System.Nullable'1[System.Boolean]' cannot be used for return type 'System.Boolean'

THINK I AM GETTIGN CLOSE...Any thoughts on the error....

Do I leave the "child" in the Query above _"Function(child) child.CB_ID"_ ., or do I replace this with a tabel name?

----------


## jaykappy

Anyone?
Is there something that I can test?  The query?  What its trying to return?  I am at a loss here...

----------


## jaykappy

THINK I GOT IT....YEAAAAAAAAAA......Will get back to this forum and paste everything I have...

Hopefully I got it.....Stay tuned....if anyone is even reading this anymore...
.

----------


## MattP

> Stay tuned....if anyone is even reading this anymore...
> .


Really!?  For a 2 day old thread?

Here's a couple of articles on working with related data.

Walkthrough: Displaying Related Data in a Silverlight Business Application

RIA Services and relational data

I would recommend creating another method on your domain service with a logical name like GetAddressesByBusinessID and pass in selectedItem.ID there.



```
    Public Function GetAddressesByBusinessID(ByVal businessID) As IQueryable(Of Address)
        Return GetAddresses.Where(Function(a) a.CB_ID = businessID)
    End Function
```



```
ctx.Load(ctx.GetAddressesByBusinessIDQuery(selectedItem.ID))
```

It'll remove some of the logic from your code behind to the Domain Service where it belongs.

----------

