LINQ Expression Trees on the Compact Framework 22 Sep 2008


Red Church, Blue Sky A week ago, I was writing about the ability to use Mono's System.Core to run C# 3 and LINQ applications on .net 2. A few months ago, I was writing about the new LINQ provider that friends at db4o released. This LINQ provider uses LINQ expression trees to optimize LINQ queries, turning them into db4o's native query language. Today I'm going to write about a cute new hack from our friends at db4o. If the 3.5 version of the Compact Framework comes with a System.Core, and a LINQ to objects implementation, it doesn't contain the namespace System.Linq.Expressions, which is used by all optimized LINQ providers. What those fine folks did, was simply to take Mono's implementation of this namespace. There was one issue with that approach. Expression Trees can be compiled at runtime, and that uses System.Reflection.Emit, that the Compact Framework doesn't have. A nice thing is that folks at Mainsoft contributed to Mono's System.Core an expression interpreter, which allows you to use the full LINQ expression trees without using System.Reflection.Emit. They sent me the patches they have for the expression interpreter to make it pass the full test suite we have, so I'll integrate it shortly. And voilĂ , just by using Mono's implementation of System.Core, and by hacking a little in it, to make it compile on the Compact Framework, they've been able to produce a new assembly, System.Linq.Expressions.dll. You just have to reference it in your Compact Framework project, and it will let you use LINQ expression trees, which allows you to write optimized LINQ providers for the Compact Framework. Of course, this is completely open-source and licensed under the MIT/X11. For now, you can find the code in db4o's repository, but I'll backport the changes they did to the LINQ expression interpreter, so that people that want to use it can use our code base directly. Congrats to you guys for making the finest choice in the third party code you ship!