When you use SDS, you can retrieve your data in two ways.
You can retrieve authorities, containers, and entities directly by URI.
Alternatively, you can scope queries at the service, authority, or container
levels to retrieve direct descendants subject to the query criteria and
conditions.
Let's start by looking at how to retrieve authorities,
containers, and entities directly. To retrieve an item, simply address an HTTP
GET request to the appropriate URI. For example, to retrieve the coho authority, address your HTTP
request to the authority URI:
https://coho.data.beta.mssds.com/v1/
The service
responds with an XML payload that contains the authority metadata:
<s:Authority xmlns:s="http://schemas.microsoft.com/sitka/2008/03/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:x="http://www.w3.org/2001/XMLSchema">
<s:Id>coho</s:Id>
<s:Version>3593083</s:Version>
</s:Authority>
Remember that the Version property value is a
non-incremental system-generated number. In other words, if you've just created
an entity, don't assume that the version number will be 1.
To retrieve the CohoSauvignon05 entity, address your
HTTP request to the entity URI:
https://coho.data.beta.mssds.com/v1/wines/cohosauvignon05
Note: In this URL, coho represents your authority, wines represents your container, and cohosauvignon05 represents your entity.
The service responds with an XML representation of the
entity:
<RedWine xmlns:s='http://schemas.microsoft.com/sitka/2008/03/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:x='http://www.w3.org/2001/XMLSchema' >
<s:Id>CohoSauvignon05</s:Id>
<s:Version>210441</s:Version>
<vineyard xsi:type='x:string'>Coho Vineyard</vineyard>
<vintage xsi:type='x:string'>2005</vintage>
<grape xsi:type='x:string'>Cabernet Sauvignon</grape>
<region xsi:type='x:string'>New Zealand</region>
<description xsi:type='x:string'>Full-bodied and fruity</description>
<thumbnail xsi:type='x:base64Binary'>/9j/4AAQSkZJ… </thumbnail>
<price xsi:type='x:decimal'>16.95</price>
</RedWine>
You'll notice that this matches the XML payload we used
earlier to create the entity, except that this also includes a Version element.
While these basic fetch operations are fine if you know
exactly what you're looking for, in most cases you will want to specify queries
to provide more sophisticated data retrieval.
SDS supports a simple, text-based query syntax, based on the
C# Language Integrated Query (LINQ) pattern. Each query takes the following
format:
from
e in entities [where condition] order by [property] select e
The from e in
entities format applies regardless of whether you are retrieving
authorities, containers, or entities. In SDS, authorities, containers, and
entities are all types of flexible entity. The scope of your query determines
the type of flexible entity (authority, container, or entity) that your query
will return. For example, if you scope a query to an authority, your query will
return containers. Similarly, if you scope a query to a container, your query
will return entities.
You can use comparison operators to add conditions to your
queries. You can also use Boolean operators to concatenate or further
manipulate your conditions. The current beta version of SDS supports the
following operators.