Using serializable values
At some point you may need to store objects in the database that are either impossible to map using NHibernate (the object may be of a type you have no control over) or the resulting relational model would simply be too complex. As long as the objects are of a type that is serializable (using BinaryFormatter
), NHibernate can save and retrieve them transparently.
In this recipe we'll show a crude NHibernate based error log, which stores raised Exception
s, complete with any nested InnerException
s.
Getting ready
Complete the Getting ready instructions at the beginning of this chapter.
How to do it…
Add a new folder named
SerializableValues
to theMappingRecipes
project.Add a new class named
Error
to the folder:public class Error { public virtual Guid Id { get; set; } public virtual DateTime ErrorDateTime { get; set; } public virtual Exception Exception { get; set; } }
Add an embedded mapping named
Error.hbm.xml
to the folder:<?xml version="1.0" encoding="utf-8"...