Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

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

This entry was posted in Linq, NHibernate. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://blogs.6bit.com/josh Josh Perry

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


  • http://www.ThinqLinq.com Jim Wooley

    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.

  • Kyle Baley

    @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: http://sourceforge.net/projects/rhino-tools/

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

    It includes more than

  • Jamie

    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!

  • http://weblogs.asp.net/fbouma FransBouma

    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.