Using native SQL

At some point in the development of your application, you may find that none of the NHibernate specific querying techniques really does the trick. Maybe you need to write a query with a very specific SQL, so that it performs optimally, or maybe there's a function or stored procedure that you need to use. Thankfully, NHibernate allows you to use plain SQL queries in the native dialect of your target database and dropping out to SQL doesn't mean dropping out of NHibernate.

Getting ready

Complete the Getting Ready section at the beginning of this chapter.

How to do it…

  1. Add a new folder named QueryBySql to the project.
  2. Add a new class named SqlQueries to the folder:
    using System.Collections.Generic; using NH4CookbookHelpers.Queries; using ...

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.