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…
- Add a new folder named
DynamicComponents
to theMappingRecipes
project. - 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 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.