Maps a Enum to a
DbType.String.
Namespace:
NHibernate.TypeAssembly: 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.
![]() | |
---|---|
public enum MyEnum { On, Off, Dimmed } |
all that needs to be written for your enum string type is:
![]() | |
---|---|
public class MyEnumStringType : NHibernate.Type.EnumStringType { public MyEnumStringType() : base( typeof( MyEnum ) ) { } } |
The mapping would look like:
![]() | |
---|---|
... <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..::.EnumStringType
NHibernate.Type..::.AbstractType
NHibernate.Type..::.NullableType
NHibernate.Type..::.ImmutableType
NHibernate.Type..::.EnumStringType