Open the code-behind file and add the following, using statements as well as the code that comes next:
Using statements:
using SLRIA.Web;using System.Windows.Ria.Linq;
Main Code: NWDomainContext nw = new NWDomainContext(); public MainPage(){ InitializeComponent(); dgData.ItemsSource = nw.Products; nw.Load(nw.GetProductsQuery());}
Run the page to see the data in the Products table being displayed in the Silverlight DataGrid control. Note that you can sort (on multiple columns using the Shift key), re-order and resize columns without requiring any changes.
Displaying data from related tables Now, let's make some changes to the code to not only display the products, but also the name of the supplier (from the Suppliers table) and category (from the Categories table). For this, first open the metadata file in the Web project and add a new directive '[Include]' above the members that point to the respective objects like this:
[Include]public Category Category;...[Include]public Supplier Supplier;
Now open the main domain service class and change the GetProducts method as follows:
public IQueryable GetProducts(){ DataLoadOptions loadOpts = new DataLoadOptions(); loadOpts.LoadWith(p => p.Category); loadOpts.LoadWith(p => p.Supplier); this.Context.LoadOptions = loadOpts; return this.Context.Products;}
The LoadWith statements return the category and supplier data, along with the product data to the client and can be accessed in the Silverlight XAML using standard .NET dot-notations to show the name of the product, category and supplier company in the DataGrid like this:
...
The grid is now enhanced with an auto-type filter and a pager.
A simple Silverlight-based application that shows data from 3 related tables.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.