Querying Data

One of the most common requirements of any data framework is the ability to perform queries. WCF Data Services allow two modes on the client side. The first one is utilizing query strings similarly to what it is possible to do with Uris. To accomplish this you invoke the Execute(Of T) method from the DataServiceContext class, where T is the type you want to retrieve a collection of. For example, the following code returns a collection of orders for the specified customer, sorted by order date:

image

This way is efficient but avoids the strongly typed approach provided by LINQ. Fortunately the .NET Framework also enables using a special LINQ provider known as LINQ to Data Services. The following code snippet demonstrates how you can obtain the same result as previously by writing a LINQ query:

image

Of course this is powerful but not necessarily the best choice. For example, you might want to prevent indiscriminate data access from clients, or you might simply want better performances implementing queries on the server side and exposing methods returning query results. This is where service operations take place.

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

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