Using calculated properties

A property need not, always, be represented as a column value in the database. In plain SQL, we may have used built-in or custom functions, such as string length or encryption, or perhaps even a subquery, to project the data we want to expose. NHibernate allows you to map such a construct directly to a property.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named CalculatedProperties to the MappingRecipes project.
  2. Add a class named Invoice to the folder:
    using System; namespace MappingRecipes.CalculatedProperties { public class Invoice { public virtual Guid Id { get; protected set; } public virtual decimal Amount { get; set; } public virtual string Customer ...

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.