Galin Iliev's blog

Software Architecture & Development

Using LINQ to Objects in .NET 2.0 projects

If you've played with C# 3.0 and LINQ you might feel bored with good old .NET 2.0 projects. But wait! There is a way to use LINQ to Objects in .NET 2.0 projects. LINQBridge makes this possible. But how?

First, it's important to understand that C# 3.0 and Framework 3.5 are designed to work with CLR 2.0-the same CLR version that Framework 2.0 uses. This means that the C# 3.0 compiler emits IL code that runs on the same virtual machine as before.

This makes Framework 3.5 additive-just as Framework 3.0 was additive-comprising additional assemblies that enhance the existing 2.0 Framework and CLR. So there's nothing to stop us from writing our own assemblies that do the work of Framework 3.5 (at least, the critical bits required for local LINQ queries).

Can I use LINQBridge with C# 2.0 and Studio 2005?

You can-but the query operators will be awkward to use without lambda expressions, extension methods, query syntax, etc.

More info you can find at LINQBridge official page as well as source code. Thanks to Joe Albahari!

Comments (1) -

  • Nohcs777

    5/13/2010 7:42:45 PM | Reply

    I'm using this in CLR2 with extensions.  Binding has certainly been interesting to hand old without the IQueryable interface as well as missing MethodBodies to avoid using embedded string keys for POCOs.  If you know any 3rd party stuff that has addressed these issues in CLR2 with LinqBridge, I'd certainly be interested.