Andrew Whitaker

Named Queries and Unmapped Types

This post was inspired by this StackOverflow question.

Named queries are extremely useful in a variety of situations when you’re using NHibernate. If you want to use dialect-specific features that aren’t supported in NHibernate, you’re practically forced to go this route.

Another (possibly less common scenario) is this: you’re working with a database and want to use a stored procedure. For some reason you cannot change the stored procedure.

QueryOver Series Part 8: Working With Subqueries

Subqueries are often extremely useful when building queries. Unfortunately there’s not much out there on how to work with subqueries in QueryOver. In this post, I’ll dive into how to create the subqueries using QueryOver’s various subquery APIs.

Getting NHibernate Up and Running Quickly

NHibernate can seem like a daunting library to set up. The configuration can get quite complicated—XML mappings, code mappings, mapping conventions, dialects, logging, etc. Sometimes you just want to get something up and running to test out a query or play around with a database other than your primary one. In this post, I’ll show you how to get up and running with NHibernate in about 5 minutes and in around 50 lines of code in LINQPad.

This assumes you already have a database configured and ready to create new tables and connect to with NHibernate.

QueryOver Series - Part 7: Using SQL Functions

In this post, I’ll go over how to use functions built into the database engine. This can be useful when you want to do some work inside of your SQL query rather than do post-processing on the result set you get back.

QueryOver Series - Part 6: Query Building Techniques

In this post, I’m going to explain some more advanced techniques for building queries with QueryOver. Practically, this means adding joins and where clauses dynamically. This is actually one of the most powerful abilities of QueryOver so it’s worth understanding.

QueryOver Series - Part 5: Materializing Results

So far I’ve been using the .List or .SingleOrDefault methods to actually get results from a query. In this post I’ll go into a little more detail about those methods. I’ll also cover other ways you can materialize a query’s results.

QueryOver Series - Part 4: Transforming

You might have noticed that the last post in the series always projects each result row into an object[]. This might have made you wonder if there’s a better way to get results from a QueryOver query. Well there is! It’s called transforming.

In the context of an NHibernate query, a transformer is simply a class that transforms each row from a query into an instance of an object. NHibernate comes with several and allows you to easily create a custom transformer if you’d like.

QueryOver Series - Part 3: Selecting

In this post I’ll go over building the SELECT statement with NHibernate QueryOver. I’ll also cover the different ways you can actually get a result back from your query.