Double Foreign Key Reference

5 posts, 0 answers
  1. Houdini
    Houdini avatar
    9 posts
    Member since:
    Feb 2012

    Posted 10 Feb 2012 Link to this post

    Hello, I have an issue that I would really love some help with. I will keep it simple and based around the center of issue.

    Picture this; 4 tables in database with the following stuctures.

    [AffectedParcels]
    -AffectedParcelID (PK)
    -LandValuationNo
    -VolFol
    -SurveyStatusID (FK to SurveyStatus Table)

    [SurveyStatus]
    -SurveyStatusID
    -Description

    [Aquisition]
    -AquisitionID (PK)
    -AffectedParcelID (FK to AffectedParcels Table)
    -StageID (FK to Stage table)


    [Stage]
    -StageID (PK)
    -Name
    -Description

    Now using WCF RIA and Silverlight with LINQtoSQL Data Model.
    I have a GridView and DataForm (Telerik) and the DDS's that are linked to the Domain Service.
    Now then, the GridView is bound to the AffectedParcel DDS and displays nicely.
    The DataForm is also bound to it. However, I do not want to see foreign key values. I have applied the techniques to filter out the foreign keys and return a particular field from the table instead. Therefore, instaed of seeing a field with the SurveyStatusID, I now see a combo box with a list of all the Descriptions. I will show the code that I have applied in doing so.

    The DataForm:
     <telerik:RadDataForm Name="AffectedParcelDataForm" Height="350" Width="340" Margin="80,0,0,0"
        Grid.Column="1" AutoEdit="false" AutoCommit="False" AutoGenerateFields="False"
         Header="Affected Parcels"
         ItemsSource="{Binding DataView, ElementName=affectedParcelDomainDataSource}"
         ReadOnlyTemplate="{StaticResource APTemplate}"
         EditTemplate="{StaticResource APTemplate}"
         NewItemTemplate="{StaticResource APTemplate}" HorizontalAlignment="Left"  MouseEnter="AffectedParcelDataForm_MouseEnter" VerticalAlignment="Top">
    </telerik:RadDataForm>

    The DataTeplate:
    <DataTemplate x:Key="APTemplate">
        <Grid>
        <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        </Grid.RowDefinitions>
            <telerik:DataFormDataField Label="Valuation Number"
                DataMemberBinding="{Binding LandValuationNo, Mode=TwoWay}" Width="350" />
            <telerik:DataFormDataField Label="Volume and Folio" Grid.Row="1"
                DataMemberBinding="{Binding VolFol, Mode=TwoWay}" Width="350"  />
            <telerik:DataFormDataField Label="Approximate AOT" Grid.Row="2"
                DataMemberBinding="{Binding ApproxAreaOfTake, Mode=TwoWay}" Width="350"  />
            <telerik:DataFormDataField Label="Final AOT" Grid.Row="3"
                DataMemberBinding="{Binding FinalAreaOfTake, Mode=TwoWay}" Width="350"  />
            <telerik:DataFormDataField Width="Auto" Grid.Row="4" Label="Survey Status">
                <telerik:DataFormDataField.Content>
                    <telerik:DataFormComboBoxField  
                        DataMemberBinding="{Binding SurveyStatusID, Mode=TwoWay}"
                        ItemsSource="{Binding DataView, Source={StaticResource SS}}"
                        SelectedValuePath="SurveyStatusID"
                        DisplayMemberPath="Description"/>
                    </telerik:DataFormDataField.Content>
                </telerik:DataFormDataField>
        </Grid>           
    </DataTemplate>

    SS is the key for the SurveyStatusDomainDataSource.


    Well that is all well and good. But when I try that same stunt with the Stage Field, then a real demom comes out. Why, Because adding the following code as a field in the DataTemplate:

    <telerik:DataFormDataField Label="Stage" Grid.Row="5" >
        <telerik:DataFormDataField.Content>
            <telerik:DataFormComboBoxField x:Name="StageIDCombo"
                DataMemberBinding="{Binding AffectedParcelID, Mode=TwoWay}"
                ItemsSource="{Binding DataView, Source={StaticResource A}}"
                SelectedValuePath="AffectedParcelID"
                DisplayMemberPath="StageID" />               
            </telerik:DataFormDataField.Content>
    </telerik:DataFormDataField>

    Will in fact bring back the StageID associated with the affectedParcel from the Aquisition Table. But as you can see, it's an ID that comes back - something that I don't want to see. I would want to see the Stage Name or description from the Stage table. You see my issue here? If any one can ride with me on this one I would appreciate it.
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 13 Feb 2012 Link to this post

    Hi Houdini,

    Please refer to this help article. I think that it will prove useful for you scenario.

    Regards,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Houdini
    Houdini avatar
    9 posts
    Member since:
    Feb 2012

    Posted 13 Feb 2012 Link to this post

    Trust me, I have read that article to the 'T'. I have no problem binding to a referenced table [a table referenced by a foreign key] and pulling back the field I want to display. Please understand that the problem arises when the referenced table itself also has a foreign key to another table, to which I want to pull a specific field.

    Your example gave:
    Person
    -FirstName
    -LastName
    -CountryID


    Country
    -CountryID
    -Name

    Now imagine that the Country Table had a reference to a Planet Table via PlanetID. How would I pull all this data back (with the Planet Name) and display them in my dataform?.
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 16 Feb 2012 Link to this post

    Hi Houdini,

    The approach in your scenario should be similiar to the one illustrated in the article. Unfortunately RadComboBox cannot automatically know all the AffectedParcels entries, without fetching the tables (AffectedTables, Aquisitions) on the client.

    Regards,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Houdini
    Houdini avatar
    9 posts
    Member since:
    Feb 2012

    Posted 16 Feb 2012 Link to this post

    I accomplished the task after much trial and error. The code below works:

    <telerik:DataFormDataField Label="Stage" Grid.Row="3" x:Name="StageIDCombo" DataMemberBinding="{Binding AffectedParcelID, Mode=TwoWay}">
                            <telerik:DataFormDataField.Content>
                                <telerik:RadComboBox ItemsSource="{Binding DataView, Source={StaticResource A}}" SelectedValue="{Binding AffectedParcelID, Mode=TwoWay}" SelectedValuePath="AffectedParcelID" IsEnabled="{Binding Mode,Converter={StaticResource MyConverter}, ElementName=StageIDCombo, Mode=TwoWay}"  >
                                    <telerik:RadComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition />
                                                    <RowDefinition />
                                                </Grid.RowDefinitions>

                                                <telerik:DataFormComboBoxField DataMemberBinding="{Binding StageID, Mode=TwoWay}"
                                                               ItemsSource="{Binding DataView, Source={StaticResource S}}"
                                                               SelectedValuePath="StageID"
                                                               DisplayMemberPath="Name" />
                                                <telerik:DataFormComboBoxField DataMemberBinding="{Binding StageID, Mode=TwoWay}"
                                                               ItemsSource="{Binding DataView, Source={StaticResource S}}"
                                                               SelectedValuePath="StageID"
                                                               DisplayMemberPath="Description" Grid.Row="1" />
                                            </Grid>
                                        </DataTemplate>
                                    </telerik:RadComboBox.ItemTemplate>
                                </telerik:RadComboBox>
                                
                            </telerik:DataFormDataField.Content>
                        </telerik:DataFormDataField>

    There is just one minor pinch that I am working on. The first combox shows drop down for each record in the Aquisition Table. But the second (nested) ones rightfully shows all the Names and Description of the stages.

    I really wished Maya was here, she would know what to do.
Back to Top
DevCraft banner