Parent Child-VBForums
Results 1 to 5 of 5

Thread: Parent Child

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Parent Child

    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
    Code:
        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
    Code:
            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

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Re: Parent Child

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

    Code:
            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?
    Last edited by jaykappy; Oct 18th, 2011 at 10:45 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Re: Parent Child

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

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Re: Parent Child

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

  5. #5
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Parent Child

    Quote Originally Posted by jaykappy View Post
    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.

    Code:
        Public Function GetAddressesByBusinessID(ByVal businessID) As IQueryable(Of Address)
            Return GetAddresses.Where(Function(a) a.CB_ID = businessID)
        End Function
    Code:
    ctx.Load(ctx.GetAddressesByBusinessIDQuery(selectedItem.ID))
    It'll remove some of the logic from your code behind to the Domain Service where it belongs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.