This is a C# library that serializes .NET Framework 4.0 LINQ expression trees into XML. This project was motivated by a real-life problem of reducing the response time of a massive web service, which needed another approach besides the tried solutions that rely on incremental improvements to custom XML serialization on objects ; the code just to define the serializable objects along with their own XML custom XML serializaton methods already covered hundreds of thousands of lines of code. Instead, we serialize the query and defer execution to the server, which allows us to (1) minimize network bandwidth costs, (2) reduce web service response time by as much as several orders of magnitude (depending on the query).

 

Usage

To execute LINQ queries against an IQueryProvider exposed by a remote, WCF endpoint for example: 

 

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 is more expressive and takes less lines of code to write 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).

 

Special thanks: this completes a project started by Microsoft in 2008.

Last edited May 23 at 7:07 PM by TWebster, version 16