Kyle Baley - The Coding Hillbilly

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Linq to NHibernate - The Day After

What a difference a day makes. Spent the better part of yesterday trying to figure out the Linq to NHibernate so that I could use Contains on something other than a string, like so:

from job in session.Linq( )
where officeIds.Contains( job.Office.Id )
select job;

The book Linq in Action, as well as Matt Warren's series on query providers, both provided a lot of help in understanding the code. As I started sifting through it and looking at failing tests, I started making some fairly sweeping changes to the code. Not necessarily to check it in, mind you, more for my own eddy-ficashun. I was in spike mode, not "someone else may actually look at this" mode.

In the end, it wasn't quite as hard as I first thought. 'Course, I have a built-in advantage since parsing expression trees is much like parsing the family tree, what with all the AndAlso's and OrElse's. ExclusiveOr was a new concept though.

By the time I was done, I had an ExpressionVisitor very similar to the one Matt Warren specified and I had implemented it in a couple of the visitors in the codebase. It still didn't do what I wanted but I was a lot clearer on how things flowed. It fixed a couple of bugs while introducing others and while I wasn't any further ahead in my specific task, it was a nice break to do something I haven't in a long time.

Then I updated to the latest and lo! Chadly (who I'd link to if I had a blog for him) has implemented what appears to be the same thing, albeit in a much cleaner way. And even better! Doug Mayer (also conspicuously unlinked) has implemented the exact Contains support that I needed! Well, almost. Contains works on arrays now but not on Lists (or anything deriving from ICollection methinks). But ToArray helps out there.

Anyway, here I am a day later having learned about query providers and my work still got done for me in my absence. All hail OSS!

Kyle the NHiberLinq'd


Posted 04-09-2008 8:34 AM by Kyle Baley
Filed under: ,

[Advertisement]

Comments

FransBouma wrote re: Linq to NHibernate - The Day After
on 04-09-2008 2:39 PM

On my blog I posted a lot of different Contains queries you might run into. ( I think it was episode 12 of my linq provider saga). Contains isn't as easy as it looks at first. The main gripe is that it still has to work when combined with other query elements.  

Dew Drop - April 9, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - April 9, 2008 | Alvin Ashcraft's Morning Dew
on 04-10-2008 8:55 AM

Pingback from  Dew Drop - April 9, 2008 | Alvin Ashcraft's Morning Dew

Jamie wrote re: Linq to NHibernate - The Day After
on 04-16-2008 5:11 PM

Just stumbled across your blog in an attempt to find Linq to NHibernate.  All I can find is a compiled version of something at magiconsoftware that's like a year old!  You seem to have found something under active development that I can't find anywhere...  The stuff at hookedonlinq seems to just be links to documentation.  Could you provide a link to actual code?  Thanks!

Kyle Baley wrote re: Linq to NHibernate - The Day After
on 04-16-2008 7:55 PM

@Jamie: Ah yes, I should have said something because that wasn't altogether obvious to me either at first.

Linq to NHibernate can be found as part of Ayende Rahien's Rhino Tools. You have to download the code from SourceForge: sourceforge.net/.../rhino-tools

NHibernate.Linq is found under the experiments folder. Google group for the project is at: groups.google.com/.../rhino-tools-dev

It includes more than

Jim Wooley wrote re: Linq to NHibernate - The Day After
on 04-23-2008 9:22 PM

I'm glad you found the book helpful. It's always nice to see how people can take the core of LINQ and continue to extend it for additional implementations.

Josh Perry wrote re: Linq to NHibernate - The Day After
on 04-07-2009 10:21 PM

NHibernate.Linq is now located in the NHibernate Contrib repository.

nhcontrib.svn.sourceforge.net/.../NHibernate.Linq

Add a Comment

(required)  
(optional)
(required)  
Remember Me?