Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Business Apps Example for Silverlight 3 RTM and .NET RIA Services: Part 18
Custom Linq Provider

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):

  1. VS2008 SP1 (Which includes Sql Express 2008)
  2. Silverlight 3 RTM
  3. .NET RIA Services July '09 Preview

Also, download the full demo files and check out the running application.

Here is the general application pattern we are looking at this time:

image

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)
{
return this.Context.GetSuperEmployees(pageNumber)
.Where(emp => emp.Issues > 100)
.OrderBy(emp => emp.EmployeeID)
.Select(emp =>
new MyApp.Web.SuperEmployee()
{
EmployeeID = emp.EmployeeID,
Gender = emp.Gender,
Issues = emp.Issues,
LastEdit = emp.LastEdit,
Name = emp.Name,
Origin = emp.Origin,
Publishers = emp.Publishers,
Sites = emp.Sites,
}).AsQueryable();

}

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()
{
return new LinqToSuperEmployeeService(this.context)
.Where(emp => emp.Issues > 100);
}

Basically the LinqToSuperEmployeeService parses the Linq query and gives us access to the individual parts of the query.

internal class LinqToSuperEmployeeService : QueryableService<SuperEmployee>
{
private SuperEmployeeServiceClient context;

public LinqToSuperEmployeeService(SuperEmployeeServiceClient context)
{
this.context = context;
}
protected override object ExecuteQuery(QueryDetails details)
{
if (details.Count)
{
return this.context.GetSuperEmployeesCount(
details.SkipSize,
details.PageSize,
details.OrderBy,
details.Filters.ToArray());
}
else
{
return this.context.GetSuperEmployees(
details.SkipSize,
details.PageSize,
details.OrderBy,
details.Filters.ToArray())
.Select(emp => ConvertUtils.Convert(emp));
}
}
}

For example, consider a query such as:

q.Skip(20).Take(10)
.OrderBy(e => e.Name)
.Where(e => e.Origin == "Earth");

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()]
public class SuperEmployeeDomainService : LinqToSuperEmployeeDomainService
{
public IQueryable<SuperEmployee> GetSuperEmployees()
{
return this.Context;
}

And the code for your custom DomainService?  Pretty easy as well.

public class LinqToSuperEmployeeDomainService : DomainService
{
private SuperEmployeeServiceClient webServiceContext = new SuperEmployeeServiceClient();

private LinqToSuperEmployeeService linqContext;

protected LinqToSuperEmployeeDomainService()
{
this.linqContext = new LinqToSuperEmployeeService(this.webServiceContext);
}

public IQueryable<SuperEmployee> Context
{
get { return this.linqContext; }
}

public SuperEmployeeServiceClient WebServiceContext
{
get { return this.webServiceContext; }
}
}

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.

Read the original blog entry...

About Brad Abrams
Brad Abrams is currently the Group Program Manager for the UI Framework and Services team at Microsoft which is responsible for delivering the developer platform that spans both client and web based applications, as well as the common services that are available to all applications. Specific technologies owned by this team include ASP.NET, Atlas and Windows Forms. He was a founding member of both the Common Language Runtime, and .NET Framework teams.

Brad has been designing parts of the .NET Framework since 1998 when he started his framework design career building the BCL (Base Class Library) that ships as a core part of the .NET Framework. He was also the lead editor on the Common Language Specification (CLS), the .NET Framework Design Guidelines, the libraries in the ECMA\ISO CLI Standard, and has been deeply involved with the WinFX and Windows Vista efforts from their beginning.

He co-authored Programming in the .NET Environment, and was editor on .NET Framework Standard Library Annotated Reference Vol 1 and Vol 2 and the Framework Design Guidelines.

Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE