LINQ to NHibernate

Time for another update; it's been a while since the last one. Good progress has been made on the new HQL AST Parser port from Hibernate, and it's now in a state where it's usable, passing the vast majority of the tests within the NHibernate test suite. Of those that are failing (around 8 out of over 1600), we are currently discussing on the developers group whether we will live with these minor breaking changes, or do continued work on the parser to get everything passing.

The current call is to live with the current breaks - the Hibernate AST parser fails in exactly the same way on those tests, so in terms of using Hibernate as our "specification" we are doing exactly the correct thing.

So if anyone fancies playing with the new parser, I think it's about ready. I'm not sure I'd suggest putting it in a live environment right now, but for projects that are still under development it would be great to see it in use to get it "battle hardened". It is expected that we'll get the new parser into the main NH trunk sometime in the next few days - I'll post here once it's up there so you brave souls can give it a spin.

Now, how about the LINQ side of things? That is, after all, the end game here. Well, I've only spent a few hours hacking out some code, but already with the new parser I can turn this:

    ISession session = sfi.OpenSession();
    NhQueryProvider provider = new NhQueryProvider(session)
    Query<Animal> animals = new Query<Animal>(provider);

    var x = from a in animals where a.Legs == 8 select a;

into this:

select animal0_.Id as Id0_, animal0_.Description as Descript2_0_, animal0_.BodyWeight as BodyWeight0_, animal0_.Legs as Legs0_, animal0_1_.name_first as name2_1_, animal0_1_.name_initial as name3_1_, animal0_1_.name_last as name4_1_, animal0_1_.NickName as NickName1_, animal0_1_.Birthdate as Birthdate1_, case when animal0_1_.animalId is not null then 1 when animal0_.Id is not null then 0 end as clazz_ from Animal animal0_ left outer join Human animal0_1_ on animal0_.Id=animal0_1_.animalId where animal0_.Legs=8

Now, being fair I've not actually run the SQL, but I suspect it's correct. Also, I've not yet hooked this into the execution pipeline within NH, so I'm not executing the SQL, just generating it. However, that bit should be pretty simple.

Before anyone gets too excited, the code behind this is some of the dirtiest I've ever written. For those of you that know me, you can imagine how bad it must be ;) So it's not getting checked in anywhere, since it would just be an embarrassment. However, I was interested in getting some form of proof of concept up and running, and I'm very pleased at how easy it has been (for this really simple form of query - as I said, don't get *too* excited!).

Next step is to hook this into the execution pipeline to actually get something out of the DB (only a couple of hours work here, I think). Then it's time to step back an look at the big picture to get the design correct.

Carry on watching this space...

Comments

# re: LINQ to NHibernate
Gravatar Keep up the good work. I can't wait for this to be production quality.
Left by Mick on 4/16/2009 10:37 PM
# re: LINQ to NHibernate
Gravatar I can't even begin to tell you how excited I am about getting the LINQ implementation. In every LINQ to NHibernate implementation I've found so far, SelectMany and the *OrDefault methods don't seem to work. I'll definitely be one of your early testers :)

Keep up the great work.
Left by Rob on 4/17/2009 4:00 AM
# Reflective Perspective - Chris Alcock &amp;raquo; The Morning Brew #329
Gravatar Reflective Perspective - Chris Alcock &amp;raquo; The Morning Brew #329
Left by Pingback/TrackBack on 4/17/2009 9:37 AM
# re: LINQ to NHibernate
Gravatar Im really looking forward to a solid Linq to NHibnerate implemntation. Keep up the good work !
Left by BjartN on 4/17/2009 4:00 PM
# LINQ to NHibernate
Gravatar LINQ to NHibernate
Left by makka on 4/19/2009 4:31 PM
# LINQ to NHibernate &amp;laquo; TDD developer
Gravatar LINQ to NHibernate &amp;laquo; TDD developer
Left by Pingback/TrackBack on 4/19/2009 4:36 PM
# re: LINQ to NHibernate
Gravatar Watching for the NHibernate commit.

We were looking at implementing an NHibernate LINQ provider to use in a product we have in development. The Hibernate AST is definitely the way to go and we would love to assist with this.

Is the LINQ provider going to be developed on a live SVN server at NHibernate Contrib or somewhere like that?
Left by joshperry on 4/20/2009 10:21 PM
# re: LINQ to NHibernate
Gravatar The new Linq2NHibernate place is the trunk..
this will be the right one ;)
Left by Fabio Maulo on 5/15/2009 8:28 AM
# NHibernate Modeller
Gravatar NHibernate Modeller
Left by DDL on 5/19/2009 9:11 AM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

Please add 5 and 7 and type the answer here:

Preview Your Comment.