NHibernate Query Generator with Visual Studio 2008

Custom Tool Configuration I've been using Ayende's NHibernate Query Generator (NHQG) to help type-ify my NHibernate repository queries.  One of the great +1's of his tool is that you can apply it as a Custom Tool for your NHibernate mapping files right within Visual Studio.  

With this setup, every change to my mapping file is reflected in my typed NHibernate ICriteria instances.  For those who work directly with Hibernate Expressions, look how clean my queries are:

// Get it using the Id
public static MyClass GetById(long id)
{
return Repository.Get<MyClass>(Where.MyClass.Id == id);
}
// Get those updated today
public void Example2()
{
IList<MyClass> cards = Repository.Find<MyClass>(Where.MyClass.LastUpdated >= DateTime.Today);
}

That's just awesome!

There's a slight glitch though, his installer only registers the tool for Visual Studio 2005.  I'm sure now that 2008 is RTM (I've been using Beta 2) he'll soon have a new version out, but in the mean time, you can use these two .reg files:

NHQG C# Custom Tool Registration

NHQG VB Custom Tool Registration

Published 11-19-2007 1:31 PM by cromwellryan
Filed under:

Comments

# Ryan Cromwell said on 06 December, 2007 08:45 PM

I posted recently a manual .reg file for adding the NHibernate Query Generator custom tool to Visual

# Links Today (2008-04-10) said on 10 April, 2008 08:32 AM

Pingback from  Links Today (2008-04-10)

# { null != Steve } » NHibernate Query Generator said on 26 April, 2008 04:20 PM

Pingback from  { null != Steve } &raquo; NHibernate Query Generator

# So you want to learn NHibernate? - Part 1 of 1, The Links « HSI Developer Blog said on 31 July, 2008 03:26 PM

Pingback from  So you want to learn NHibernate? - Part 1 of 1, The Links « HSI Developer Blog

# So you want to learn NHibernate? (or, NHibernate Hyperlink Acupuncture) | The Freak Parade said on 08 August, 2008 12:28 PM

Pingback from  So you want to learn NHibernate? (or, NHibernate Hyperlink Acupuncture) | The Freak Parade

# Knave said on 06 November, 2008 04:50 PM

Hi Ryan,

I can't seem to get the automated generation to work. It just creates a blank YourClass.hbm.cs file in the specified folder.

I'ved installed the installer from Ayende's site.

Using: Nhibernate 2.0.1 + VS2008 SP1 here.

# cromwellryan said on 06 November, 2008 06:42 PM

I haven't tried the Query Generator with 2.0, but just the fact that it's creating the hbm.cs file is telling us the generator is at least trying.  What version of the Generator are you using?  Did you build from trunk or download a release?

If I remember correctly (not always a good bet), if your mapping file is invalid, it will leave a blank .cs file, but hopefully you've confirmed that.

# Knave said on 07 November, 2008 12:45 AM

Well, the trunk doesn't seem to have the MSI installer code in it anymore.

I'm currently using the console app from the trunk (built myself with latest Nhibernate version) and link via external tools function VS2008.

It also doesn't work when I overwrite the executable file (from the installer) with my own built version.

Mapping files are valid, since they work fine when I used the latest built of the generator from the trunk. :(