Maps a Enum to a
DbType.String.
Namespace: NHibernate.TypeAssembly: NHibernate (in NHibernate.dll) Version: 3.2.0.4000 (3.2.0.4000)
Syntax
C# |
---|
[SerializableAttribute] public abstract class EnumStringType : AbstractEnumType |
Visual Basic |
---|
<SerializableAttribute> _ Public MustInherit Class EnumStringType _ Inherits AbstractEnumType |
Visual C++ |
---|
[SerializableAttribute] public ref class EnumStringType abstract : public AbstractEnumType |
Remarks
If your database should store the Enum
using the named values in the enum instead of the underlying values
then subclass this IType.
CopyC#
CopyC#
CopyC#
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.
![](../icons/CopyCode.gif)
public enum MyEnum { On, Off, Dimmed }
all that needs to be written for your enum string type is:
![](../icons/CopyCode.gif)
public class MyEnumStringType : NHibernate.Type.EnumStringType { public MyEnumStringType() : base( typeof( MyEnum ) ) { } }
The mapping would look like:
![](../icons/CopyCode.gif)
... <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
System..::..Object
NHibernate.Type..::..AbstractType
NHibernate.Type..::..NullableType
NHibernate.Type..::..ImmutableType
NHibernate.Type..::..PrimitiveType
NHibernate.Type..::..AbstractEnumType
NHibernate.Type..::..EnumStringType
NHibernate.Type..::..EnumStringType<(Of <(<'T>)>)>
NHibernate.Type..::..AbstractType
NHibernate.Type..::..NullableType
NHibernate.Type..::..ImmutableType
NHibernate.Type..::..PrimitiveType
NHibernate.Type..::..AbstractEnumType
NHibernate.Type..::..EnumStringType
NHibernate.Type..::..EnumStringType<(Of <(<'T>)>)>