Share via


ADO.NET Data Services : How to request your ADO.NET Data Services

Introduction

In my previous post, I explained how to create a ADO.NET Data Service with Visual Studio 2010. In this post, I will explain how to request this Data Service using Internet Explorer (but this will also work in any other browser). The database used in previous post is AdventureWorks.

Listing and filtering entities

By default when accessing the service, the list of all entities is returned.

https://localhost:34570/AdventureWorksService.svc

image

https://localhost:34570/AdventureWorksService.svc/Products 
This request lists all products existing in the database.

image

Let’s go further, you would like to return articles 6 to 7 order by ProductNumber:

https://localhost:34570/AdventureWorksService.svc/Products?$orderby=ProductNumber&$skip=5&$top=2

REST Syntax Description
$orderby=ProductNumber order Products by ProductNumber
&$skip=5 and skips the first 5 rows
&$top=2 and returns the two first rows

You could also order the results by ProductNumber descending:

https://localhost:34570/AdventureWorksService.svc/Products?$orderby=ProductNumber%20desc&$skip=5&$top=2

REST Syntax Description
$orderby=ProductNumber desc order Products by ProductNumber descending
&$skip=5 and skips the first 5 rows
&$top=2 and returns the two first rows

Here is the syntax to filter a product in particular:

https://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%201

REST Syntax Description
$filter=ProductID eq 1 where ProductID is equal to 1

https://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20ge%20900%20and%20ProductID%20lt%20950

REST Syntax Description
$filter=ProductID ge 900 where ProductID is greater or equal to 900
and ProductID lt 950 and ProductID less than 950

Other expression syntaxes are available here.

Expanding SubEntities

One of the great feature of Data Services is the ability to also return referenced entites.

image

For example, if you want to request a specific Product,  and also return the information defined in its ProductSubCategory property, the request is as follows:

https://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%20771&$expand=ProductSubcategory

REST Syntax Description
$filter=ProductID eq 771 where ProductID equals to 771
&$expand=ProductSubcategory and expands ProductSubcategory for this specific Product. ProductSubcategory is the name of the navigation property  for ProductSubcategory in the Product entity defined in your emdx file

And if you also need to retrieve the Catagory entity, which is two levels above :

https://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%20771&$expand=ProductSubcategory,ProductSubcategory/ProductCategory

REST Syntax Description
$filter=ProductID eq 771 where ProductID equals to 771
&$expand=ProductSubcategory, ProductSubcategory/ProductCategory expands ProductSubcategory for this specific Product and ProductSubcategory/ProductCategory

New features of Visual Studio 2010 beta 2

When your Data Service project is running with debugger inside VS2010, all the requests executed are listed into Visual Studio. Really great feature :-)

image