Project Description
a .NET 4.0 and Silverlight 4 class library that serializes and deserializes Expression instances. Also: a WCF IQueryable LINQ Provider and Web Http (REST) client for Silverlight that provides a simplified REST client API (i.e. WCF's WebChannelFactory) that's easier to use than WebClient.

I picked up where Luca and Luke left off in 2008 on Expression serialization, and rewrote a new Expression Serialization project that's compatible with .NET4.0 and Silverlight 4.

I worked through the bugs that existed not only in the .NET 3.5 code as it were, but also the new bugs in .NET 4.0 and Silverlight 4. Additionally, I took out the code which was DLINQ or Entity Framework -dependent and replaced this with a more generic code that will work with any data access layer (even ADO.NET classic).

So this is a .NET 4.0 and Silverlight 4 class library that serializes and deserializes Expression instances (from System.Linq.Expressions). What this enables a developer to do is:

  1. write LINQ queries in familiar C# syntax on the client side,
  2.  then send them over the wire to a WCF service, and
  3. then execute the LINQ query on the server-side.

You can just use the straight Expression serialization methods, but the project also has a working implementation of a IQueryProvider

Update: new LINQ Provider project now available:


This has some basic similarities to the capabilities provided by WCF Data Services (or WCF RIA services). For example, there's an IQueryProvider (RemoteQueryProvider) that lets you execute LINQ queries against a remote WCF service.

  1. To execute LINQ queries against the remote WCF IQueryProvider we use the following pattern of use (in Silverlight):


Task.Factory.StartNew(() => 


IQueryable<Customer> queryable = from c in new Query<Customer>()

 where c.ID <= 30

 && c.Country == "Spain"

 || c.ContactTitle == "Owner"

 select c;


List<Customer> results = queryable.ToList();

int count = queryable.Count();



which in my opinion feels more familiar and a little less work than


EntityQuery<Customer> entityQuery =from c in context.GetCustomersQuery()

where c.ID <= 30

 && c.Country == "Spain"

 || c.ContactTitle == "Owner"

 select c;

System.ServiceModel.DomainServices.Client.LoadOperation<Customer> loadOp

= context.Load<Customer>(entityQuery, true);

var entities = loadOp.Entities;

loadOp.Completed += (a, b) =>


var list = entities.ToList();

_customers = list;



that you get with WCF RIA Services. (In .NET 4.0 you can completely leave out the call to (TaskFactory.StartNew).

2 components which I included and updated:

  1. The Expression Tree serialization API: A general purpose XML serialization of Expression Trees. This works over any expression tree (ConstantExpression, MemberExpression, and yes even LambdaExpression and MethodCallExpression, and so on). I've worked through most of the bugs I think.
  2. An IQueryable implementation wrapping the client side of the WCF service: The client-side calling syntax is simplified by providing an IQueryable implementation. My implementation uses a class RemoteProvider that implements IQueryProvider. When the LINQ query needs to be executed, it serializes the Expression of the query to XML and sends it to the WCF server to be executed.

Other changes:

  • Where ExpressionSerializer used reflection and the run-time could be narrowed down to a limited set of possiblities (such as a Expression), I opted to use T4 Text Templates to auto-generate the code instead.
  • Any ConstantExpression of non-primitive, non-string Type were just represented as their .ToString(). I rewrote the code so that you can provide some KnownType(s) and DataContractSerializer will serialize their ConstantExpression values into the serialized Expression.
  • Remote queries are executed against a Web HTTP (REST) WCF service.


Future Plans:

  • serialize/deserialize expressions as JSON.


09/14/2011 - update

I just came across the LINQ IQueryable Toolkit today. I haven't looked at the source yet, but I would encourage you to check out their project also.

Last edited Sep 30, 2011 at 2:36 AM by TWebster, version 14