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.
Add a new folder named
CalculatedProperties
to theMappingRecipes
project.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; set; } public virtual int InvoicesOnCustomer { get; protected set; } } }
Add a new embedded mapping named
Invoice.hbm.xml
to the folder:<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns=...