Database Reference
In-Depth Information
Add a new class to the project. This class will be used to create the connection
to the OData service, define and execute the query against the OData service,
and load the Docs collection that will bind to the UI. For this example, name
the new class TechBioModel .
When you've added all the components discussed, your Solution Explorer should look like Figure 7-
16. You're ready to start adding some code.
7.
Figure 7-16. Solution Explorer
Open the TechBioModel class, and add the following namespaces. These
namespaces provide additional functionality needed to query your OData
source and work with collections. For example, the
System.Collections.ObjectModel namespace contain classes that can be used
as collections in the object model of a reusable library. The
System.Data.Services.Client namespace represents the Silverlight client
library that your application uses to access the data service:
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Data;
using TechBioModel;
using System.Data.Services.Client;
using System.Collections.ObjectModel;
9.
8.
Add the following code to the TechBioModel class. This class calls out to your
OData service. First, you initialize a new TechBio object (the object you created
via the DataSvcUtil and added to your project) using the URI to your OData
service. Then, you execute a LINQ query and populate your Docs
DataServiceCollection which is used to bind to the list box on the phone's
user interface. In this example, the query asks for all the document data from
the Docs table (Entity) where the AuthorID is 113:
public MainViewModel()
{
Search WWH ::




Custom Search