Rants Tagged with “Data Services”
1 2 3 > >> (Total Pages: 3/Total Results: 28)
I just found out that my changes to the article and code for Silverlight 2 RTW are now live. The article makes the small change that it no longer requires you to use EdmGem to build your proxy (using the Service Reference instead). I've also updated the code example to be compatible with .NET 3.5 SP1 and Silverlight 2.
In case you're not familiar with this MSDN Magazine article, it covers how to implement data access using ADO.NET Data Services and Silverlight 2 including reading and writing data. Let me know if you have questions about it.
I've finally had a chance to update my Silverlight 2-ADO.NET Data Services example. In this new sample I show how to create a Line-of-Business application (an XBox Game editor) using ADO.NET Data Services against both an Entity Framework model and NHibernate. Unlike earlier examples, this one includes implementation against the ADO.NET Data Service Silverlight 2 library to support saving of changed entities. In addition, I show some techniques for paging, retrieving simple types over an ADO.NET Data Service and full styling of the application. I hope to add support for Forms Authentication in the coming weeks.
Feel free to post replies with questions about the sample.
If you are thinking about using SQL Data Services (the data part of the Azure stack) in your Silverlight 2 project, think again. As you might know, ADO.NET Data Services (Astoria) will not work cross-domain regardless of a security policy file (because of some limitations in the two networking stacks that Silverlight 2 uses). Its a problem but in most use-cases ADO.NET Data Services (Astoria) is used on the same domain so no biggie...but...
The Azure SQL Data Service uses Astoria to expose their data to the client...that means that with the ADO.NET Client Library that you can't access SQL Data Services. The reality is that since SQL Data Services requires basic authentication, it would not be terribly secure to call it in any case but this seals the deal.
The only good news is that since Astoria is just REST, you might be able to do the work to call it manually using WebClient or HttpWebRequest but its not an easy fix.
Too bad too, it would have been a great mix...SL2 + SDS.
Today at 3pm CST (4pm EST, 1pm PST) I will be doing a LiveMeeting talk on ADO.NET Data Services. If you are not at the PDC this week, drop by NotAtPDC.com and check out my session!
There is a known problem with ADO.NET Data Services today that is important if you (or your server) lives in specific timezones. The problem is associated with the way that the Silverlight Data Services Library constructs their URI for searches.
The problem surfaces if you do a query that has a DateTime comparison in it. For example:
var qry = from o in ctx.Orders
where o.OrderDate <= dt
select o;
This query generates the following URI in the EST timezone in the US:
http://.../ProductService.svc/Orders()?$filter=OrderDate le datetime'2008-10-13T00:00:00-04:00'
This works great. The problem is that in other timezones (e.g. Bulgaria) where its forward of Greenwich Mean Time, so the UTC date is +03:00 like so:
http://.../ProductService.svc/Orders()?$filter=OrderDate le datetime'2008-10-13T00:00:00+03:00'
Because the "+" isn't URL Encoded, it becomes a space which makes the date incorrect. For now you can convert the date to universal time but that's a hack at best:
var qry = from o in ctx.Orders
where o.OrderDate <= DateTime.Today.ToUniversalTime()
select o;
It works but its a hack.
In building my Silverlight RC example using ADO.NET Data Services for Entity Framework and NHibernate I ran into what I think is a common pattern. I am writing an editor for XBox game data. The model for this data uses decorator tables in the database which are modeled as a common "Product" class and derived "Game", "Console" and "Accessory" classes. In the application I am using paging to only look at fifty results at once. This works fine on both sides.
But one of the pieces of information I wanted was a list of all the Game Genre. This became problematic as ADO.NET Data Services wanted me to retrieve all 880 games in order to get a list of these Genres (of which there are only 20 some odd). The whole idea of using paging is go avoid the huge overhead of bringing down the whole entity. Interestingly when I executed a LINQ query that used projection into non-entities, the query wasn't supported as projection isn't allowed in the ADO.NET Data Services URI model (which the client uses).
What ADO.NET Data Services does allow is to create Service Operations (e.g. WebGet or WebInvoke) on the Data Service to extend the model for specific cases. There are some limitations (must return IEnumerable<T>, IQueryable<T> or void) but this works pretty well. The difference between returning IEnumerable and IQueryable is whether system queries can be applied to them. Returning a fixed list (my need) meant to return a IEnumerable<T> list. Intersting that ADO.NET Data Services support returning an IEnumerable<T> of primitive types. For example my operation was spec'd as:
[WebGet]
public IEnumerable<string> Genres()
{
}
This works and returns a simple XML file with the primitive values. But alas the Silverlight Data Service Client doesn't support non-entities. I tried using the DataServiceContext.BeginExecute() to call this service and it threw an exception that it couldn't materialize non-entity classes. Hrmph!
This was a case where adding a quick web service call to get this data on the server and return it would have been the easy road, but that's not how I roll, is it?
After confirming this behavior with the Data team, I decided to write an extension to the DataServiceContext class to support this. In this little piece of code, the same pattern of calling DataServiceContext.BeginXXX is used. To make this work I simply use the HttpWebRequest class to do a simple GET to the server's URI syntax and use LINQ to XML to convert the data into the simple types (String in my case).
I've started to help out with some new ideas on the CodePlex SilverlightContrib project so I thought this was the perfect place for this code. Its not packaged up yet in a build (and probably won't be until sometime after RTW ships) but if you want to grab it you can grab the latest checkin I made:
SilverlightContrib ChangeSet 41005
I'll be shipping this new demo as soon as RTW ships (its not done yet). Look for the announcement here.
It has come to my attention that my current examples using ADO.NET Data Services are performing very badly. I was using that example as anecdotal evidence that Data Services performed slower than the Web Service counterparts. I don't think this is accurate. I am working on some performance comparisons that I will share on my blog once Silverlight 2 goes into a full release so I can be sure that the numbers reflect a real-world release.
The issue seems to surround a bone-headed query I was making:
var qry = from p in TheContext.Products.Expand("Supplier").Expand("Category")
orderby p.ProductName
select p;
This means for every product I was retrieving its related Category and Supplier. The problem is that I was duplicating this data (since some products shared Categories and Suppliers). Not efficient at all.
When I re-release these examples when Silverlight 2 ships, I will be hosting the examples on CodePlex. Watch here for announcements on the release of the code, new versions of the examples as well as the performance comparisons coming soon.
I've uploaded a new version of my code from my Silverlight 2/Data Services MSDN Article. I took the new Silverlight 2 Data Services client that was released and updated the code example. If you want to get the code, you can download it from my site here:
http://wildermuth.com/downloads/sl2_ds_example.zip
I've also changed and updated the examples (more elaborate versions of the article code) using it on the Silverlight Data site, including both the Entity Framework and the NHibernate examples. Let me know if find any bugs.
Mike Flasko to the rescue! The ADO.NET Data Services Team has released an interim build of the ADO.NET Data Services Library to address .NET 3.5 SP1 incompatibilities. While this is just a stop-gap measure, its of great relief that I announce this news as my new MSDN Magazine article was broken because of the incompatibility.
Follow the link for all the information, warnings and download links. As Mike says, this is an interim build to address the incompatibility but that you shouldn't rely on it for production machines. The real build will come with Silverlight 2's release whenever that actually happens.
As some of you may have seen, my new article in MSDN Magazine (and online) was recently published. Because we're in a bit of a no-mans-land with builds, the current article only works with .NET 3.5 SP1 Beta and Silverlight 2 Beta 2. This means if you're like most of the world and updated to the full release of .NET 3.5 SP1, some of the code in that article is not going to work for you. I hope to have a new drop of the code (and maybe the article too) once Silverlight 2 ships and is fully compatible with ADO.NET Data Services/Entity Framework that are in the full version of .NET 3.5 SP1. See my other article talking about the incompatibilities here:
My apologies to anyone who spent too much time trying to get the code in the article working. Such is the problem with beta software and hopefully we'll have a solution sooner rather than later.