Tuesday, December 7, 2010

Linq Expression Evaluation

If you have a Linq Expresssion (such as a reference to a variable in the closure) or really any other self-contained fragment, you can easily evaluate it by turning it into a lambda expression. For example, I was trying to evaluate the content of a variable that was showing up as a ".x" field. To do so, I did the following:


Saturday, December 4, 2010

NHibernate 3.0

NHibernate 3.0.GA has been released!  It has all sorts of goodies like QueryOver, logging abstraction, and tons more.  It also now has a built-in LINQ provider.  Unfortunately, the LINQ provider is still in a beta state.  Many queries work (as evidenced by the hundreds of working unit tests), but there are also still many queries it has trouble with.  If you'd like to help accelerate the development of the LINQ provider (or any other part of NH for that matter), here's what you can do:
  1. File issues when you find bugs.  http://jira.nhforge.org/
  2. Vote for issues.  Popularity is difficult to gauge if we don't hear back from people.
  3. Provide test cases for those issues.  A complete test case is easier to digest than a tiny code fragment without context.  If the test can be used directly, the team member working on the issue can spend more of their time making improvements instead of trying to recreate a test.
  4. If you're feeling ambitious, dig into the source code and try to work out a fix.
There's a great article on making tests for NHibernate here.  I've also included some different steps that might help you out.
  1. Check out the trunk using something like TortoiseSVN (https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate)
  2. Use ShowBuildMenu.bat to create the AssemblyInfo.cs files.
  3. Load up NHibernate.Everything.sln in Visual Studio.
  4. Create a test with the issue number in the NHSpecificTest folder of the NHibernate.Test project (NH2392 is a fairly simple example to copy from).
  5. Use ShowBuildMenu.bat to see how to set up your database connection and run all the tests.
  6. Create a patch (TortoiseSVN can help you with this) and attach it to the JIRA issue.
With your help, we will work towards a rock solid LINQ release that matches the tremendous power and reliability already provided by the NHibernate platform.

Sunday, September 26, 2010

Interesting Changes in NHibernate 3.0

There are tons of new features in NHibernate 3.0. I'm going to highlight a few minor interesting ones from my view.

Client Profile Support
The .NET client profile is now supported out of the box.  Castle.Core also supports the client profile as well, so the Castle bytecode provider will work out of the box as well.  Great news for those who write desktop apps.

Logging Abstraction
In getting support for the client profile, log4net was an issue.  It hasn't been updated in ages and doesn't support the client profile itself.  This issue combined with other people's desire for a logging abstraction now means that NHibernate supports pluggable loggers.  You can use the NHibernate.Logging package to get support for libraries such as Common.Logging.  This also enables use of the excellent NLog framework, which is actively updated.

Polymorphism in Get and Load
Previously, Get and Load methods on the session required the exact mapped type.  Now, they allow you to specify a class or interface higher up the inheritance hierarchy, as long as there's only one match.  This will allow people to eliminate their own mapping layers when it comes to retrieving objects by primary key.  Importantly, this will make ActiveRecord work much better with interfaces.

Fixes for IdBag
The identifier bag had a bunch of bugs, especially ones that manifest themselves more when used in rich client applications.  If you had problems before, try it again.

ISQLFunction Argument Repetition
[Update: This will not be included in 3.0]

Though it's not in the trunk, I'm also excited about the potential inclusion of NH-2318.  This will let us write functions for dialects that have non-trivial argument patterns.  For example, a NullSafeEquals function could be written as (?1 IS NULL AND ?2 IS NULL) OR (?1 IS NOT NULL AND ?2 IS NOT NULL AND ?1 = ?2).  With the current code, such a function breaks because it repeats arguments.  The patch also deals with argument reording or removal, but it doesn't support ordinal parameters at the moment.  We'll see if this one happens to make it in.

All in all, NHibernate 3.0 is a very exciting release that many contributors have put a lot of hard work into.