In this blog post we will talk about peculiarities of using IDataStore WCF services in Silverlight projects. As you guess, the main restriction is that all inquiries should be performed asynchronously or rather should not block the UI thread.
Let’s extend the solution from the WCF services for IDataStore blog by adding a new Silverlight Application project to it. Then, we will add references to DevExpress.Data and DevExpress.Xpo assemblies and an existing Persistent.cs file with the Customer class definition.
Next, we will drop the GridConrtol (gridControl1) component onto the main page and modify the MainPage.xaml file as shown below:
1: <UserControl x:Class="SilverlightApplication1.MainPage"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5: xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6: mc:Ignorable="d"
7: d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
8: xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
9: <Grid x:Name="LayoutRoot" Background="White">
10: <dxg:GridControl x:Name="gridControl1" AutoPopulateColumns="True">
11: </dxg:GridControl>
12: </Grid>
13: </UserControl>
14:
Finally, we will modify the MainPage class code in the following way:
1: using DevExpress.Xpo;
2: using DevExpress.Xpo.DB;
3: ...
4: namespace SilverlightApplication1 {
5: public partial class MainPage : UserControl {
6: Session session = null;
7: public MainPage() {
8: InitializeComponent();
9: //Initialize connection settings in a separate thread.
10: ThreadPool.QueueUserWorkItem(o => {
11: //Create connection to our WCF Service.
12: XpoDefault.DataLayer = XpoDefault.GetDataLayer(
13: "http://localhost:64466/Service.svc",
14: AutoCreateOption.SchemaAlreadyExists
15: );
16: session = new Session();
17: //It is necessary to call UpdataSchema method for all persistent classes.
18: session.UpdateSchema(typeof(Customer));
session.TypesManager.EnsureIsTypedObjectValid();
19: Dispatcher.BeginInvoke(BeginInitializeDataSource);
20: });
21: }
22: void BeginInitializeDataSource() {
23: var query = from c in session.Query<Customer>()
24: where c.Country.Length > 2
25: select c;
26: //Execute the query asynchronously.
27: query.EnumerateAsync(EndInitializeDataSource);
28: }
29: void EndInitializeDataSource(IEnumerable<Customer> result, Exception ex) {
30: //Assign the data source to the control.
31: gridControl1.DataSource = result;
32: }
33: }
34: }
35:
If we run the application, we will see the following results:

Happy XPOing in Silverlight!
Free DevExpress Products - Get Your Copy Today
The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the
DevExpress Support Center at your convenience. We'll be happy to follow-up.