Immutable entities
An immutable entity is an entity that never changes once it has been created. An example could be entries in event log. New log entries may be added all the time; however, once saved, they are not supposed to be modified.
This behavior could of course be enforced in code, or perhaps even in the database, but if we tell NHibernate to treat specific classes as immutable, we can both enforce the immutability and allow NHibernate optimize performance a bit.
Getting ready
Complete the Getting ready instructions at the beginning of this chapter.
How to do it…
Add a new folder named
ImmutableEntities
to theMappingRecipes
project.Add a new class named
LogEntry
to the folder:using System; namespace MappingRecipes.ImmutableEntities { public class LogEntry { public virtual Guid Id { get; protected set; } public virtual string Message { get; set; } } }
Add a new embedded mapping named
LogEntry.hbm.xml
to the folder:<?xml version="1.0" encoding="utf-8" ?> <hibernate...