|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
From the Blogosphere Business Apps Example for Silverlight 3 RTM and .NET RIA Services: Part 18
Custom Linq Provider
By: Brad Abrams
Aug. 4, 2009 05:00 PM
Continuing in our discussion of Silverlight 3 and the update to .NET RIA Services. I have been updating the example from my Mix09 talk “building business applications with Silverlight 3”. RIA Services is very much an extension of the LINQ project. Effectively you can think of RIA Services as n-tier LINQ. As such, I thought it would be interesting to show how any of the tons of Linq Providers can be used with RIA Services. You can watch the original video of the full session The demo requires (all 100% free and always free):
Also, download the full demo files and check out the running application. Here is the general application pattern we are looking at this time: Way back in Part 8: WCF I showed off how to get your data from a WCF services (rather than Entity Framework) via RIA Services. One part I was never quite happy with is that I needed to pass the page number into the Query method. While David Poll and I developed a neat little paging pattern that worked with this, it certainly felt like a hack.. and Jason Allor, our development manager totally agreed. The core problem is I didn’t have a IQueryable that knew about my WCF services to return. Jason assured me this would be easy to do based on the LINQ to TerraServer Provider Sampleand Matt Warren’s excellent set of posts. So I dared him to try it and he did! What Jason ended up with is pretty cool. It does not cover 100% of the cases that RIA Services might use, but it does cover a lot or them and all the source is here, so feel free to use and extend.
In my original WCF example, my query method looked like: public IQueryable<SuperEmployee> GetSuperEmployees(int pageNumber) } Notice that page number should really be handled by skip() and take() in the query rather than an explicit parameter that doesn't compose well. And with Jason's cool new IQueryable to WCF implementation it is much clearner: public IQueryable<SuperEmployee> GetSuperEmployees() Basically the LinqToSuperEmployeeService parses the Linq query and gives us access to the individual parts of the query. internal class LinqToSuperEmployeeService : QueryableService<SuperEmployee> For example, consider a query such as: q.Skip(20).Take(10) We'd end up calling the GetSuperEmployees(20,10,null,{"Earth"}); The base QueryableService will parse out the the SkipSize, PageSize and orderby information an puts it in the QueryDetails class. And then in the this overload of the Execute method we pluck those out and pass them on to the WCF service. You could just as easily pluck those values out and call a REST based service or generate some TSQL, etc. If you wanted to reuse this functionality for your WCF service, you just derive your own subclass of QueryableService and do the right thing with the values. One more cool thing, if you create your own subclass of of DomainService that can handle calling a particular WCF service things get even easier. [EnableClientAccess()] And the code for your custom DomainService? Pretty easy as well. public class LinqToSuperEmployeeDomainService : DomainService This part talked about how to use a custom Linq provider to make it very easy to call a WCF service to get data into your Silverlight client. The very simple Linq provider I show here can be easily customized to work with any service or other data source. Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||