I have two tables in a database and using entity framework and ria services to display data in a simple datagrid. Here is the database/EF structure
Cars Make
----- ----
CarId MakeId
Car Make
MakeId
In my Silverlight datagrid I want to show the following two columns, for example
Car Make
--- -----
Escort Ford
Megane Renault
Rav4 Toyota
I can easily bind to the Cars table and show cars but I can't work out how to display the Make taken from the child table
The xaml that I am using to configure the datagrid is as follows:
<datagrid:DataGrid x:Name="CarGrid" AutoGenerateColumns="False" MinHeight="100" IsReadOnly="True" ItemsSource="{Binding ElementName=MyData, Path=Data}">
<datagrid:DataGrid.Columns>
<datagrid:DataGridTextColumn Header="Car" Binding="{Binding Car}"/>
<datagrid:DataGridTextColumn Header="Make" Binding="{Binding Cars.Make}"/>
......
The datagrid datasource binds to a DomainDataSource method "GetCars". I'm not sure if it is automatically loading the child table (not sure whether I have to explicitly tell it to or not, and have no idea how to do this in xaml).
I'm sure I could ditch the xaml and do it in c# but I'm trying to be a good coder and do it in xaml.
Best Answer
I find a good solution. Let's try this: http://jeffhandley.com/archive/2010/03/12/lookupdata.aspx
Then don't forget to "include" your child table in the Query lookup on your domain service class.
ex:
replace the names with your own.
PS: remember to do all the steps that the blog indicates.