1
votes

I'm using EF4 and have a entity in my domain model called Applications. Applications has a navigation property called Status. The Status Entity contains 2 fields, StatusID and StatusName. I'm displaying a DataGrid that shows the details of Applications. I have decorated the Application Metadata with the [Include] attribute, and have also modified the GetApplicationsQuery to have an .Include("status") statement. The ItemsSource for the grid is set in code using a Linq query.

If I set AutoGenerateColumns on my DataGrid to true, the status column indicates that there is a status object, so it looks like the Includes are working correctly. I now want to set AutoGenerateColumns to false and manually build the datagrid (to only show a few columns), but I can't find how to bind the StatusName field (belonging to the status navigation property) to one of the columns. The code below obviously doesn't work as i'm effectively binding the Status column to an object, but what is the correct way to bind to a field on a navigation property?

<telerik:GridViewDataColumn Header="App Name" DataMemberBinding="{Binding AppName}"/>
<telerik:GridViewDataColumn Header="Commentary" DataMemberBinding="{Binding Commentary}"/>
<telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding **status**}"/>

I've tried binding to status.StatusName, but i'm just guessing now. Any help would be appreciated.

Thanks

M

1

1 Answers

0
votes

Found the problem.

Instead of using the queries defined in the DomainService (GetApplicationsQuery in this instance), I was using a Linq query (from a in ctx.applications where ..........).

The generated GetApplicationsQuery had the .Include("status") statements added, but my manual Linq query didn't.

I set my DataGrid ItemsSource to use the GetApplicationsQuery().Where(a=>.... and I was then able to access the navigation property using the 2 part name, status.StatusName.

M