Maps a Enum to a DbType.String.

Namespace:  NHibernate.Type
Assembly:  NHibernate (in NHibernate.dll)

Syntax

Visual Basic (Declaration)
<SerializableAttribute> _
Public MustInherit Class EnumStringType _
	Inherits ImmutableType _
	Implements IDiscriminatorType, IIdentifierType, IType, ICacheAssembler,  _
	ILiteralType
C#
[SerializableAttribute]
public abstract class EnumStringType : ImmutableType, 
	IDiscriminatorType, IIdentifierType, IType, ICacheAssembler, ILiteralType
Visual C++
[SerializableAttribute]
public ref class EnumStringType abstract : public ImmutableType, 
	IDiscriminatorType, IIdentifierType, IType, ICacheAssembler, ILiteralType
JavaScript
NHibernate.Type.EnumStringType = function();

Type.createClass(
	'NHibernate.Type.EnumStringType',
	NHibernate.Type.ImmutableType,
	NHibernate.Type.IDiscriminatorType,
	NHibernate.Type.IIdentifierType,
	NHibernate.Type.IType,
	NHibernate.Type.ICacheAssembler,
	NHibernate.Type.ILiteralType);

Remarks

If your database should store the Enum using the named values in the enum instead of the underlying values then subclass this IType.

All that needs to be done is to provide a default constructor that NHibernate can use to create the specific type. For example, if you had an enum defined as.

 Copy Code
            public enum MyEnum 
            {
            	On,
            	Off,
            	Dimmed
            }
            

all that needs to be written for your enum string type is:

 Copy Code
            public class MyEnumStringType : NHibernate.Type.EnumStringType
            {
            	public MyEnumStringType()
            		: base( typeof( MyEnum ) )
            	{
            	}
            }
            

The mapping would look like:

 Copy Code
            ...
            	<property name="Status" type="MyEnumStringType, AssemblyContaining" />
            ...
            

The TestFixture that shows the working code can be seen in NHibernate.Test.TypesTest.EnumStringTypeFixture.cs , NHibernate.Test.TypesTest.EnumStringClass.cs , and NHibernate.Test.TypesTest.EnumStringClass.hbm.xml

Inheritance Hierarchy

See Also