1 Attachment(s)
[RESOLVED] RIA Include Related Tables
I'm having an issue getting related tables to show up where I have multiple one-to-many relationships and getting them to show up using a LinqToEntitiesDomainService. (See attached image)
Here's my code for retrieving my entities:
Code:
Public Function GetLoansByLoanID(ByVal LoanID As Integer) As IQueryable(Of LoanMaster)
Return Me.Context.LoanMaster _
.Include("Borrower") _
.Include("Borrower.Signer") _
.Where(Function(x) x.LoanID = LoanID)
End Function
Here's the relevant part of my metadata file:
Code:
Friend NotInheritable Class LoanMasterMetadata
<Include()> _
Public Borrower As EntityCollection(Of Borrower)
Public EntityState As EntityState
End Class
Friend NotInheritable Class BorrowerMetadata
Public EntityState As EntityState
Public LoanMaster As LoanMaster
<Include()> _
Public Signer As EntityCollection(Of Signer)
End Class
Friend NotInheritable Class SignerMetadata
Public EntityState As EntityState
Public Borrower As Borrower
End Class
Here's the wireup for displaying my loan master entity (which works)
Code:
<dataform:DataForm x:Name="LoanDetails" Header="Loan Information"
AutoGenerateFields="False" AutoEdit="False" AutoCommit="False"
ItemsSource="{Binding ElementName=MyData, Path=Data}" HeaderVisibility="Collapsed" MinWidth="640" >
Here's the wireup for displaying my Borrowers entity (which works)
Code:
<datagrid:DataGrid x:Name="BorrowerGrid" MinHeight="100" IsReadOnly="True"
ItemsSource="{Binding ElementName=MyData, Path=Data.Borrower}" />
Here's the wirup for displaying my Signers entity (which doesn't work)
Code:
<datagrid:DataGrid x:Name="SignerGrid" MinHeight="100" IsReadOnly="True"
ItemsSource="{Binding ElementName=MyData, Path=Data.Borrower.Signer}" />
At this point it appears the issue is with with my Binding because when I step through MyData.DataView.CurrentItem.Borrower.Item(0).Signer.Item(0) in the debugger I'm getting the expected data. I can't figure out which Path to provide to get this to display though.
If anyone could help me out it would be greatly appreciated.
Re: RIA Include Related Tables
I had to handle the SelectionChanged event of my BorrowerGrid and load the Entities into the DomainContext.
Code:
Private Sub BorrowerGrid_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
Me.SignerGrid.ItemsSource = Nothing
ctx.Signers.Clear()
Dim selectedBorrower = CType(BorrowerGrid.SelectedItem, Borrower)
If selectedBorrower IsNot Nothing Then
Dim borrowerID = selectedBorrower.BorrowerID
Me.SignerGrid.ItemsSource = ctx.Signers
ctx.Load(ctx.GetSignersByBorrowerIDQuery(borrowerID))
End If
End Sub