I am currently using an enumeration in an NHibernate mapped as follows..
public enum UploadMethod
{
Java, Silverlight, Gears, Flash
}
class UploadMethodType : EnumStringType
{
public UploadMethodType() : base(typeof(UploadMethod), 255) { }
}
public class Person
{
/* Bunch of non interesting properties... */
public UploadMethod PreferredUploadMethod { get; set; }
}
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Person" lazy="false" table="[dbo].[People]">
<!-- Bunch of non interesting properties... -->
<property name="PreferredUploadMethod" type="UploadMethodType" />
</class>
</hibernate-mapping>
Which works perfectly except that the database is far from normalized, every row in the People table has a column containing one of four text strings. I've now separated this into a new table, but I'm not sure how to create the mapping in NHibernate. My first instinct was just <many-to-one>
but I don't want this enumeration to be its own entity, I basically just need NHibernate to do a simple join to tack on the extra column.
As a stop gap I just created a view, which works fine, but I'd rather that abstraction layer be in my NHibernate mapping, not the schema.