Dynamic components

Sometimes there is a need to add more columns to a table, but the code model can't be updated to accommodate this. Can we still add the columns, persist, and query their values? Yes, NHibernate provides a way to do map table columns into a key-value IDictionary, instead of individual properties of the class. This is called a dynamic-component.

Getting ready

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

How to do it…

  1. Add a new folder named DynamicComponents to the MappingRecipes project.
  2. Add a new class named Contact to the folder:
    using System; using System.Collections; namespace MappingRecipes.DynamicComponents { public class Contact { public Contact() { Attributes=new Hashtable(); } public virtual Guid ...

Get NHibernate 4.x Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.