9.5. WDS 1.5

WDS version 1.5 is included with VS2010 and adds a number of features, such as the ability to limit the number of data items returned and the ability to produce web-friendly feeds (mapping of AtomPub items).

NOTE

The team even says in the future that they are looking at implementing an offline mode for WDS.

9.5.1. RowCount and Server-Driven Paging

One of the main issues when working with WDS previously was that there was no way of knowing how many results would be returned. This made it impossible to page through data and work with WDS efficiently. WDS 1.5 now offers the ability to query how many results are returned through the $count and $inlinecount operators.

9.5.1.1. $count

$count will return just a single text value indicating the number of rows for a specific query. The following URL shows how to return a count of the orders:

http://localhost/Chapter9/MovieService.svc/Orders/$count

Note that if the count was applied to a set of 100 and the $skip, $top, or $take operators are also applied, then the number returned is the count after the $skip or $take operator is applied.

9.5.1.2. $inlinecount=allpages

$inlinecount=allpages returns a count of the number of items along with the current query results. It will return the count of items, ignoring any $skip or $take operators (the opposite of $count). The count is contained in a new m:count element (m stands for metadata). The following example demonstrates using this feature on the Orders table:

http://localhost/Chapter9/MovieService.svc/Orders?$inlinecount=allpages

If you examine the XML, you will find the following new element that indicates the inline count:

<m:count>4</m:count>

9.5.2. Limiting Number of Results Returned

You can limit the number of results returned from a call to WDS with the new Config.SetResourcePageSize() method. The following method limits queries to the Orders table to return just two results:

config.SetEntitySetPageSize("Orders", 2);

If more results are available than the page size, then WDS will also supply a next link, which can be accessed to retrieve subsequent pages:

<link rel="next" href="http://localhost/Chapter9/MovieService.svc/Orders?$skiptoken=2" />

Currently there is no client-side support for this functionality, although the WDS team says it intends to add it to a future release.

9.5.3. Projections

Projections allow you to tell WDS to return only certain item types; they are created by adding the $select operator to your query. Here's an example:

http://localhost/Chapter9/MovieService.svc/Orders?$select=Firstname,Lastname

Note that version 2 of WDS must be enabled for this feature to be used:

config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

You can also use complex types and navigation properties when using projections:

http://localhost/Chapter9/MovieService.svc/Orders?$select=Firstname,Lastname,OrderItems

The previous query returns a link to the complex type or navigation property, but you can also use the $expand operator to return the details from the related item. The following query returns the Firstname and Lastname, along with OrderItems details:

http://localhost/Chapter9/MovieService.svc/Orders?$select=Firstname,Lastname,OrderItems&
$expand=OrderItems

9.5.4. Friendly Feeds

It is now possible to map EF model properties to individual AtomPub elements. In the film example, you could map a director's name to AtomPub's author element. It is also possible to create custom classes and control how these are formatted in the output.

For more information on these features, please refer to http://blogs.msdn.com/phaniraj/archive/2009/03/21/ado-net-data-services-friendly-feeds-mapping-clr-types.aspx.

9.5.5. Miscellaneous Improvements

The WDS team has made a number of other improvements:

  • WDS 1.5 supports two-way data binding (DataServiceCollection), which is great for WPF/Silverlight scenarios. For more information, please see Chapter 15 and this blog entry:

    http://blogs.msdn.com/astoriateam/archive/2009/09/17/introduction-to-data-binding-in-silverlight-3-with-ctp2.aspx

  • It has improved support for streaming large sets of binary data.

9.5.6. What's the Relationship Between WDS and WCF RIA Services?

Scott Guthrie spoke to RedDevNews.com about whether .NET RIA Services is going to be preferred over ADO.NET Data Services for Silverlight data access (note that ADO.NET Data Services hadn't changed its name at this point):

"No. The bits that are being released today for RIA Services actually build on top of ADO.NET Data Services. So you can think of ADO.NET Data Services as providing a kind of lower-layer RAW/REST API and then RIA Services as a layer on top. We definitely think that there are scenarios where you would want to have a pure REST service model. And then the .NET RIA Services gives you things like the validation, cross-tiering, and higher-level services on top. We've worked hard to layer them nicely, so that RIA Services isn't a competitive technology but actually just builds on top of ADO.NET Data Services."

http://reddevnews.com/articles/2009/07/13/interview-with-scott-guthrie-on-silverlight-3.aspx

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.4