ADO.NET Data Services
I’m really impressed with what is happening around the ADO.NET Services (aka Astoria).
Think ‘RESTful’ url queries to entities in a way to abstracts out the particular underlying IQueryable provider.
This really does create a technology (as in Entity Framework vs. L2S vs. NHibernate.Linq) agnostic layer.
From the link above – a good set of video’s to watch (short and to the point):
How Do I …
- How Do I: Getting Started with ADO.NET Data Services over a Relational Database
- How Do I: Getting Started with ADO.NET Data Services over a Non-Relational Data Source
- How Do I: Consuming an ADO.NET Data Service in a Silverlight Application
- How Do I: Consume an ADO.NET Data Service in a .NET Application
More on Querying: (how client queries relate back to the ADO.NET Services protocol RESTful queries)
Further Reading:
Lost in Tangent has a series of Training blog posts
—
I do see ADO.NET Data Services as a great fit to behave as the service layer to your underlying domain entities model.
One thing that Mike Flasko demonstrates in the video (and Mike Taulty’s video) is the ability to query using several approaches…
I have two here:
var entities = new BistroEntities(new Uri("http://localhost:56987/BistroWebDataServices.svc")); var query = from c in entities.Companies where c.CompanyID.Equals(new Guid("56e0d889-5f54-4e2d-805b-9ba700e6b9e4")) select c; var company = query.SingleOrDefault(); company.Note = "Updated on " + DateTime.Now; entities.UpdateObject(company); entities.SaveChanges(); DataServiceContext context = new BistroEntities(new Uri("http://localhost:56987/BistroWebDataServices.svc")); context.IgnoreMissingProperties = true; var q = context.Execute<Companies>(new Uri("/Companies", UriKind.Relative)); var testCo = (from c in q where c.CompanyID.Equals(new Guid("56e0d889-5f54-4e2d-805b-9ba700e6b9e4")) select c).SingleOrDefault(); testCo.Note = "Updated on " + DateTime.Now; context.UpdateObject(testCo); context.SaveChanges();
It is interesting to see the result of the ‘var’ query above:
{http://localhost:56987/BistroWebDataServices.svc/Companies(guid'56e0d889-5f54-4e2d-805b-9ba700e6b9e4')}
It is possible to drill down further, ie. to get all the contacts at a company assuming a 1 to many relationship:
{http://localhost:56987/BistroWebDataServices.svc/Companies(guid'56e0d889-5f54-4e2d-805b-9ba700e6b9e4')/Contacts}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
You can make RESTful Uri queries, just as example of two:
http://localhost:56987/BistroWebDataServices.svc/Companies?$filter=startswith(Name,%20%27Test%27) http://localhost:56987/BistroWebDataServices.svc/Companies?$orderby=Name
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
The first one queries the underlying Company entity object (which is mapped to the Companies table) and does a startswith query on the property of ‘Name’.
The second query does an orderby query by Company name.
Cool stuff
(It’s no surprise that a decision was made by the RIA.NET Domain Services team to use ADO.NET DataServices as it’s underlying protocol).
For those with a close eye to detail, note the ‘unit of work’ with the ability to send the ‘UpdateObject’ – there is also the ability to send changes back with a batch update:
ie.
entities.SaveChanges(SaveChangesOptions.Batch);
For an advanced topic, check out using ‘Modeling Data for Efficient Access at Scale’ w/Azure & ADO.NET DataServices – good video !
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }