In my previous post, I showed how to instantiate LINQ to SQL DataContext using ObjectDataProvider in WPF. With ADO.NET Entities you can do something similar:
<Grid.Resources> <ObjectDataProvider x:Key="customers" ObjectType="{x:Type local:NorthwindEntities}" MethodName="get_Customers"> </ObjectDataProvider> <ObjectDataProvider x:Key="orders" ObjectType="{x:Type local:NorthwindEntities}" MethodName="get_Orders"> </ObjectDataProvider> </Grid.Resources>
The tricky part is to call desired property getter: MethodName="get_Customers"! :)
Now we can bind our first RadGridView completely codeless to Customers ObjectDataProvider:
<telerik:RadGridView Grid.Row="1"Margin="5"Name="RadGridView1"IsReadOnly="True"telerik:Theming.Theme="Vista"
ItemsSource="{BindingSource={StaticResource customers}}">
</telerik:RadGridView>
and load Orders programmatically in the second RadGridView for select Customer:
void RadGridView1_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e) { ObjectQuery<Orders> orders = (ObjectQuery<Orders>)((ObjectDataProvider)Grid.FindResource("orders")).Data; string customerID = ((Customers)RadGridView1.SelectedItem).CustomerID; RadGridView2.ItemsSource = orders.Where<Orders>(o => o.CustomerID == customerID); }
[Download]
Vladimir Enchev is Director of Engineering, Native Mobile UI & Frameworks