Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
NHibernate 4.x Cookbook

You're reading from   NHibernate 4.x Cookbook Over 90 incredible and powerful recipes to help you efficiently use NHibernate in your application

Arrow left icon
Product type Paperback
Published in Jan 2017
Publisher Packt
ISBN-13 9781784396428
Length 448 pages
Edition 2nd Edition
Arrow right icon
Authors (4):
Arrow left icon
 Liljas Liljas
Author Profile Icon Liljas
Liljas
Darshan Joshi Darshan Joshi
Author Profile Icon Darshan Joshi
Darshan Joshi
 Zaytsev Zaytsev
Author Profile Icon Zaytsev
Zaytsev
Jason Dentler Jason Dentler
Author Profile Icon Jason Dentler
Jason Dentler
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

NHibernate 4.x Cookbook Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. The Configuration and Schema FREE CHAPTER 2. Models and Mappings 3. Sessions and Transactions 4. Queries 5. Improving Performance 6. Testing 7. Data Access Layer 8. Extending NHibernate 9. NHibernate Contribution Projects Index

Using result transformers


In normal query scenarios we can rely on NHibernate's mechanisms to convert the query results into entities and objects that we can use. Sometimes, however, the queries may not map to classes we have defined in the mappings or maybe we want to customize what is returned. NHibernate provides many extension points and one of those is a result transformer, which can be injected into the flow of a query. It transforms the results of a query into the results that we need.

In the following recipe, we will try out two of the most commonly used built-in transformers.

How to do it…

  1. Complete the steps in the Getting Started section at the beginning of this chapter.

  2. Add a new folder named ResultTransformers to the project.

  3. Add a new class named Recipe to the folder:

    using System;
    using NH4CookbookHelpers;
    using NH4CookbookHelpers.Queries.Model;
    using NHibernate;
    using NHibernate.Transform;
    
    namespace QueryRecipes.ResultTransformers
    {
      public class Recipe : QueryRecipe
      {
        protected...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images