Expression tree serialization code posted on Code Gallery - Luca Bolognese

Expression tree serialization code posted on Code Gallery

Luca -

☕ 1 min. read

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 se­ri­al­iza­tion API: A gen­eral pur­pose XML se­ri­al­iza­tion of Expression Trees. This should work over any ex­pres­sion tree - though there are in­evitably bugs. The se­ri­al­iza­tion for­mat is fairly crude, but has been ex­pres­sive enough to sup­port the va­ri­ety of ex­pres­sion trees I’ve tried throw­ing at it.
  2. A wrap­per for se­ri­al­iz­ing/​de­se­ri­al­iz­ing LINQ to SQL queries: A wrap­per around the ex­pres­sion se­ri­al­izer al­lows se­ri­al­iz­ing LINQ to SQL queries and de-se­ri­al­iz­ing into a query against a given DataContext.
  3. A WCF ser­vice which ac­cepts se­ri­al­ized query ex­pres­sion trees and ex­e­cutes against a back-end LINQ to SQL: To en­able query­ing across tiers, a WCF ser­vice ex­poses ser­vice meth­ods which ex­e­cute se­ri­al­ized queries. The ser­vice im­ple­men­ta­tion de­se­ri­al­izes the queries against its LINQ to SQL con­nec­tion.
  4. An IQueryable im­ple­men­ta­tion wrap­ping the client side of the WCF ser­vice: The client-side call­ing syn­tax is sim­pli­fied by pro­vid­ing an IQueryable im­ple­men­ta­tion. This im­ple­men­ta­tion, RemoteTable, ex­e­cutes queries by se­ri­al­iz­ing the query ex­pres­sion tree and call­ing the ap­pro­pri­ate ser­vice. The ob­ject model that the ser­vice user is able to query against is im­ported by the WCF ser­vice ref­er­ence per the DataContracts on the LINQ to SQL map­ping 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 continues to work hard to get out the next version

0 Webmentions

These are webmentions via the IndieWeb and webmention.io.