Question

I have a silverlight project where I need a datagrid to display data from my database model. For simplicity ill use the following model.

The data grid should display articles that have been submitted but not approved. Each 'Article Submission' has an 'Author' that can be accessed through a navigation property.

I need to have a data grid that has fields from both the 'Article Submission' and the 'Author' tables.

<sdk:DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding ElementName=articleApplicationDataSource,Path=Data}" 
Name="articleSubmissionDataGrid" 
RowDetailsVisibilityMode="VisibleWhenSelected">
   <sdk:DataGrid.Columns>  
   ...some column template definitions

      <!--THIS LOADS FINE!-->
      <sdk:DataGridTextColumn x:Name="articleTitleColumn"
      Binding="{Binding Path=Title}" Header="Title" />

      <!--THIS DOESN'T-->
      <sdk:DataGridTextColumn x:Name="authorNameColumn"
      Binding="{Binding Path=Author.Name}" Header="Name" />

  </sdk:DataGrid.Columns>
</sdk:DataGrid>

So assuming my 'Author' entity is getting loaded into 'articleSubmissionDataSource' (It seems to be). Is my binding path=Author.Name the correct way to access the 'Author' entity through the navigation property?

BTW: 'articleApplicationDataSource' is being set in xaml by a 'riaControl' like this.

<riaControls:DomainDataSource AutoLoad="True" 
d:DesignData="{d:DesignInstance my1:ArticleSubmission, CreateList=true}" Height="0"
LoadedData="roleApplicationDomainDataSource_LoadedData"
name="articleSubmissionDomainDataSource" 
QueryName="GetArticleSubmissionsQuery" Width="0" LoadSize="500">
     <riaControls:DomainDataSource.DomainContext>
               <my:OrganizationContext />
     </riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>

Also, I've noticed my GetArticleSubmissions method of my domain service returns valid information for the 'Author' Navigation Property. However when I examine the 'LoadedDataEventArgs e' the 'Author' Navigation Property seems to be set to null.

Here's the code in my domain service

public IQueryable<RoleApplication> GetRoleApplications()
{
     return this.ObjectContext.ArticleSubmissions.Include("Person");         
}

Metadata for ArticleSubmission

internal sealed class ArticleSubmissionMetadata
    {

        // Metadata classes are not meant to be instantiated.
        private ArticleSubmissionMetadata()
        {
        }

         [Include]
        public Author Author { get; set; }

        public DateTime Date { get; set; }

        public int ID { get; set; }

        public int AuthorID { get; set; }

        public string Title { get; set; }
    }
}

Please, Please, Please help. If you don't understand the big mess of code I've posted then just point me to references that explain how to bind a entity and a navigation property entity together in one place.

Also if you notice any practices that are wrong the code please let me know. I didn't write any of this but I'm been given the task of making it work. I'm new to silverlight.

Was it helpful?

Solution

... Turns out everything I listed above is correct. My Problem is I had my .include("Author) on the wrong query!!!! I'll leave this up as a sample in case anyone else has this issue. I found it hard to find example text.

If your coming here for help make sure you have the include("Person") in your domain service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top