DataSource for Entity Framework in WPF > Master-Detail Binding |
As we've already seen in the Server-Side Filtering|document=WordDocuments\C1DataStudio-WPF.docx;topic=Server-Side Filtering example, C1DataSource supports master-detail binding. With very large datasets, server-side filtering is by far the best solution, but with smaller datasets, client-side filtering can be just as efficient. This next scenario demonstrates client-side master-detail binding using a grid, instead of a combo box like in our previous example|document=WordDocuments\C1DataStudio-WPF.docx;topic=Server-Side Filtering, to select our categories.
To implement master-detail binding, follow these steps:
ItemsSource="{Binding ElementName=c1DataSource1, Path=Categories}"
Or you can type it directly in XAML:
ItemsSource="{Binding ElementName=c1DataSource1, Path=Categories/Products}"
This form of the Path parameter in binding, using "/"”, Path=Categories/Products, causes the grid to automatically show the products that belong to the category that is currently selected. Running this on a single machine, as you probably are, you won't notice any significant time lapse as you select new categories in the master grid, and their respective products are displayed in the details grid. In the background, the C1DataSource is making use of an Entity Framework feature, implicit lazy loading, meaning that products are only being summoned for new categories as they are selected. For many scenarios, this is perfectly acceptable, but we began this section by specifically referring to master-detail relationships in small datasets. We might just as well fetch all of the products for all of the categories when the form loads and then display will be instantaneous whether on a single machine or across a network. To achieve this behavior, open the ViewSourceCollection editor and type Products in the Include property of the Categories view source.