re-motion Team Blog

From the Team

Major re-linq overhaul finished: the democratization of LINQ

with 6 comments

As Fabian recently posted, re-linq just got its body parts reassembled. This is good news for everyone who wants to create a capable LINQ provider. Fabian has the details, but let me phrase it for mere mortals like myself.

Creating LINQ providers used to be a pain. It looked easy from a distance, since LINQ is similar to most query languages in many ways (including SQL, NHibernate’s HQL, Entity Framework’s Entity SQL or even the querying part of XQuery). How hard can it be to transform a LINQ abstract syntax tree (AST) to any of those? The problem is, LINQ won’t give you such a tree, but something entirely different that is really hard to translate to anything.

The main trick of re-linq is that it gives you exactly what you’d have expected in the first place: an AST that resembles the LINQ statement you wrote. Plus some infrastructure to make your transformations (including visitors and a few stock transformations you’re likely going to need) and other stuff (like creating additional queries for eager fetching).

Now finally creating a LINQ provider is as simple as you would think. You don’t know what the hack transparent identifiers are and how they make your live harder? Now you don’t have to. We believe it’s perfectly possible to create a very powerful LINQ provider in a few weeks. If you want to support every conceivable LINQ query, it’s going to be a bit more, depending on how different your target language is from LINQ. But still, there’s a lot in re-linq that helps you achieve even that.

Fabian explains how to use re-linq here, and Markus Giegl has a nice sample on CodeProject that shows how to do this. We’ll keep you updated. For the brave, here’s our latest build.

This probably matters most for the NHibernate team. They just released a LINQ provider that supports basic query scenarios, but they plan to switch to a new one that uses their new HQL AST model. Using re-linq, they will hopefully be able to quickly create a provider that surpasses the old one’s capabilities by far. Steve Strong is already working on it.

– Stefan

Written by Stefan Wenig

September 4th, 2009 at 1:27 pm

Posted in LINQ,NHibernate,re-linq

6 Responses to 'Major re-linq overhaul finished: the democratization of LINQ'

Subscribe to comments with RSS

  1. Great to hear the progress being made! I’m running on a version about a week old, so will be upgrading to the latest in the next few days. So far, re-linq is definitely proving valuable with the Linq to NHibernate work – the vast majority of what I’m doing is working out how to map the Linq (or should I say re-linq) expression to HQL – there’s almost no messing about with Linq itself (and the joys of things like transparent identifiers!). I’m making good progress, and will hopefully be able to write a post about the details in the next couple of weeks.

    Steve Strong

    4 Sep 09 at 15:36

  2. That’s what we were hoping! I will follow your progress under the September sun in Italy though, and Fabian is OOF too. Mathias might be able to help you over the next two weeks.

    Stefan Wenig

    4 Sep 09 at 15:41

  3. I receive the following error when the Max() or Min() linq methods are used like the example below shows
    var highestBidder = (from b in bidders
    select b).Max(b => b.Price);

    Do you know how I can fix this?

    Message: Error binding to target method.

    Type: System.ArgumentException
    Source: mscorlib
    ParamName: null
    TargetSite: System.Delegate CreateDelegate(System.Type, System.Object, System.Reflection.MethodInfo, Boolean)
    HelpLink: null
    Stack: at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
    at Remotion.Data.Linq.Clauses.StreamedData.StreamedSingleValueInfo.ExecuteQueryModel(QueryModel queryModel, IQueryExecutor executor)
    at Remotion.Data.Linq.QueryModel.Execute(IQueryExecutor executor)
    at Remotion.Data.Linq.QueryProviderBase.Execute[TResult](Expression expression)
    at System.Linq.Queryable.Min[TSource,TResult](IQueryable`1 source, Expression`1 selector)
    at LinqToExcel.Tests.Convention_IntegrationTests.min() in C:WorkingReLinqToExcelsrcLinqToExcel.TestsConvention_IntegrationTests.cs:line 212


    14 Oct 09 at 17:18

  4. Paul,

    this is a bug in re-linq that should be fixed in build 1.13.23; the one that is available for download above. It’s definitely fixed on the trunk, I’ve just tried it out. What build are you using?

    BTW, we have a discussion group for developers using re-motion now so that discussions won’t get hidden in the comments of our blogs any longer. I’ve copied your question there:…/a9ac0c43a677d378


    Fabian Schmied

    15 Oct 09 at 07:18

  5. I am a Chinese,my English very bad . I have a question.

    there is a table:
    create table Test(
    ID int primary key identity(1,1) not null,
    Name nvarchar(50) not null,
    Recommend tinyint not null)

    ID Name Recommend
    1 aa 3

    in linq to sql,we can use:
    there is nothing problem ,
    but in linq to nhibernate:
    there is a exception (not supported).

    must we use "session.CreateQuery("from Test o where (o.Recommend&1)=1").List<Test>();" ?



    5 Dec 09 at 10:41

  6. Looks like you’re using bitwise operations. It’s very likely that those are not supported in either NH provider, because they would not be high priority – and the providers are not complete (yet).

    re-linq only passing this part of the expression on to the actual provider, so you should talk to the people responsible for LINQ to NH:

    BTW, they’ll want to know whether you’re using the old LINQ provider from nhcontrib or the new one from the trunk (only the new one is based on re-linq). The old one is hardly maintained, but I guess the new one will eventually support it.

    Stefan Wenig

    6 Dec 09 at 20:29

Leave a Reply