Expression tree serialization code posted on Code Gallery

-

Luke and I worked on this last year for one week do­ing pair pro­gram­ming. It is a good sam­ple of how you can se­ri­al­ize LINQ ex­pres­sion trees to xml.

The sam­ple in­cludes these com­po­nents:

  1. An Expression Tree serialization API: A general purpose XML serialization of Expression Trees. This should work over any expression tree - though there are inevitably bugs. The serialization format is fairly crude, but has been expressive enough to support the variety of expression trees I’ve tried throwing at it.
  2. A wrapper for serializing/deserializing LINQ to SQL queries: A wrapper around the expression serializer allows serializing LINQ to SQL queries and de-serializing into a query against a given DataContext.
  3. A WCF service which accepts serialized query expression trees and executes against a back-end LINQ to SQL: To enable querying across tiers, a WCF service exposes service methods which execute serialized queries. The service implementation deserializes the queries against its LINQ to SQL connection.
  4. An IQueryable implementation wrapping the client side of the WCF service: The client-side calling syntax is simplified by providing an IQueryable implementation. This implementation, RemoteTable, executes queries by serializing the query expression tree and calling the appropriate service. The object model that the service user is able to query against is imported by the WCF service reference per the DataContracts on the LINQ to SQL mapping on the server side

The sam­ple is here. Enjoy!

2 Comments

Comments

Charlie Calvert's Community Bl

2009-01-14T00:03:19Z

Welcome to the 48th Community Convergence. The C# team con­tin­ues to work hard to get out the next ver­sion