Mapping enumerations
An improperly mapped enumeration can lead to unnecessary updates. In this recipe, we'll discuss why and show you how to map an enumeration property to a string field.
How to do it…
Add a new folder named
Enumerationsto theMappingRecipesproject.Add the following
AccountTypesenum to the folder:public enum AccountTypes { Consumer, Business, Corporate, NonProfit }Add the following
Accountclass:public class Account { public virtual Guid Id { get; set; } public virtual AccountTypes AcctType { get; set; } public virtual string Number { get; set; } public virtual string Name { get; set; } }Add an embedded NHibernate mapping document named
Account.hbm.xmlwith the following class mapping:<class name="Account"> <id name="Id"> <generator class="guid.comb" /> </id> <natural-id> <property name="Number" not-null="true" /> </natural-id> <property name="Name" not-null="true" /> <property name...