CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Kyle Baley - The Coding Hillbilly

"We are stuck with technology when what we really want is just stuff that works" -- Douglas Adams

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


Published Apr 09 2008, 08:34 AM by Kyle Baley
Filed under: ,

Comments

FransBouma said:

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.  

# April 9, 2008 2:39 PM

Dew Drop - April 9, 2008 | Alvin Ashcraft's Morning Dew said:

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

# April 10, 2008 8:55 AM

Jamie said:

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!

# April 16, 2008 5:11 PM

Kyle Baley said:

@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

# April 16, 2008 7:55 PM

Jim Wooley said:

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.

# April 23, 2008 9:22 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!