Old code based on nhibernate summer of code (cleaned up)