15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

894 ❘ ChaPTer 32 dAtA services<br />

The same syntax works for relations, accessing properties from related entities:<br />

Menus(3)/Category/Name<br />

To get just the value without the surrounding XML content of an entity, you can use the $value query<br />

function:<br />

Menus(3)/Category/Name/$value<br />

Getting back to complete lists, you can get the number of entities in a list with $count . $count is only<br />

available with V2 of the AtomPub protocol.<br />

Menus/$count<br />

Getting just the fi rst entities of a list is done with the top query string option $top :<br />

Menus$top=2<br />

You can skip a number of entities with $skip . $skip <strong>and</strong> $top can be combined for implementing paging<br />

functionality.<br />

Menus$skip=2<br />

Filtering entities can be performed with the $filter query string option <strong>and</strong> by using the logical operators<br />

eq (equal), ne (not equal), <strong>and</strong> gt (greater than), ge (greater than or equal to):<br />

Menus$filter=Category/Name eq 'Appetizer'<br />

The result can also be sorted with the $orderby query string option:<br />

Menus$filter=Category/Name eq 'Appetizer' & orderby=Price desc<br />

For only getting a projection, a subset of the available properties, $select can be used to specify the<br />

properties that should be accessed:<br />

Menus$select=Name, Price<br />

using WCf daTa serViCes WiTh The ado.neT enTiTy frameWorK<br />

Now that you ’ ve learned the basic concept of Data Services, passing AtomPub or JSON data across simple<br />

HTTP requests, let ’ s get into a more complex example, using the ADO.<strong>NET</strong> Entity Framework for the data<br />

model, a Web application for hosting, <strong>and</strong> clients performing LINQ queries across a network that make use<br />

of classes from the System.Data<br />

.Services.Client namespace.<br />

asP.neT hosting <strong>and</strong> edm<br />

First you have to create a new project. This<br />

time a Web Application project named<br />

RestaurantDataServiceWeb is used to host<br />

the service. The new data model is created with<br />

the help of the ADO.<strong>NET</strong> Entity Data Model<br />

(EDM) template <strong>and</strong> uses the tables Menus <strong>and</strong><br />

Categories from a Restaurant database, as shown<br />

in Figure 32 - 4, to create the entity classes Menu<br />

<strong>and</strong> Category .<br />

figure 32-4<br />

Chapter 31, “ADO.<strong>NET</strong> Entity Framework,” explains how to create <strong>and</strong> use ADO<br />

.<strong>NET</strong> Entity Data Models.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!