What is it?
Proxy classes are individual class files for each datasets of the data services. This allow developers to easily call the datas in the datasets available without much effort. However, the proxy classes are only available for C# development. Imagine, having to call or to instantiate individual datas in the datasets, it would be much faster using our pre-generated proxy class.
Why should I use proxy classes?
The next question developers have in mind would be “Why use proxy classes?“. With proxy classes, it simplifies your developement by allowing .NET to process all the consumation of data back end. Hence, lesser to code compared to the previous example. One of the amazing things proxy classes allow developers to leverage on is the ability to select certain datas from the dataset and display it any way you want it to with just 5 lines of codes using LINQ.
How can I use it? (Using LINQ)
With the proxy classes provided, we can use LINQ to make data calls much easier and faster. In our previous tutorials and examples, we showed you how to call the data service using List<DataEntry>. But now, with just 5 lines of codes you can get the same results.
To get you started, let’s start with the prerequisites to get things running if you are intending to use LINQ to make data calls to the datasets of the proxy classes.
1) Download and install this framework: ADO.NET Data Services v1.5 CTP2
2) In Visual Studio 2008/2010, start a new ASP.NET Web application project
3) [Go to] Add Reference > Browse Tab > C:\Program Files\ADO.NET Data Services V1.5 CTP2\bin\Microsoft.Data.Services.Client.dll
4) Import in the relevant *Proxy.cs class file into your project (For example, STBProxy.cs)
5) Import the necessary references and libraries that you need
6) You are ready to go!
Let’s start with a simple example to pull all the datas from Singapore Tourism Board (STB) Dataset using GridView.
Add a GridView to your aspx page and by default the name should be GridView1. The code below shows the *.aspx.cs back end C# code snippet.
Code Snippet
protected void Page_Load(object sender, EventArgs e)
{
STBModel.STBEntities stbEntities = new STBModel.STBEntities(new Uri("http://api.projectnimbus.org/stbodataservice.svc/"));
stbEntities.SendingRequest += ModifyRequest;
GridView1.AutoGenerateColumns = true;
GridView1.DataSource = stbEntities.PlaceSet.ToArray();
GridView1.DataBind();
}
private static void ModifyRequest(object sender, SendingRequestEventArgs e)
{
e.Request.Headers.Add("AccountKey", "YourAccountKeyHere");
e.Request.Headers.Add("UniqueUserID", Guid.NewGuid().ToString());
}
What’s after this?
With these few lines of codes, you are now able to retrieve all the datas in the respective datasets. Now, the question is, ”How are we to retrieve only the information that we want from the datasets?”. It’s very simple! Still using LINQ, we will now select only the datas that we want to display from the dataset.
We shall take for example “PlaceID, Name and URL” from the dataset. All we need to do is to modify a single line of code from the above example.
Code Snippet
protected void Page_Load(object sender, EventArgs e)
{
STBModel.STBEntities stbEntities = new STBModel.STBEntities(new Uri("http://api.projectnimbus.org/stbodataservice.svc/"));
stbEntities.SendingRequest += ModifyRequest;
GridView1.AutoGenerateColumns = true;
GridView1.DataSource = stbEntities.PlaceSet.ToArray(); < Remove this line
GridView1.DataSource = (from c in stbEntities.PlaceSet select new { c.PlaceID, c.Name, c.URL }).ToArray();
GridView1.DataBind();
}
private static void ModifyRequest(object sender, SendingRequestEventArgs e)
{
e.Request.Headers.Add("AccountKey", "YourAccountKeyHere");
e.Request.Headers.Add("UniqueUserID", Guid.NewGuid().ToString());
}
And Voila! It’s that simple to retrieve the selected datas from any datasets. With LINQ, your development on ASP.NET Web Application is made easy with just a few lines of codes.
Signed off: Kenneth Ham

Pingback: Using LINQ in Nimbus | Project Nimbus