Mapping enums in NHibernate

649 views
Skip to first unread message

graphicsxp

unread,
May 20, 2009, 11:38:05 AM5/20/09
to nhusers
Hello,

This is my first attempt at mapping an enum with NHibernate and I'm
having an error :

NHibernate.MappingException: Could not determine type for:
NHibernate.Type.EnumStringType`1[[Metrica.SourceScope, Metrica]],
NHibernate, for columns: NHibernate.Mapping.Column(ScopeID)


Here's my mapping:

<property type="NHibernate.Type.EnumStringType`1[[Metrica.SourceScope,
Metrica]], NHibernate" name="Scope" column="ScopeID" />

And the Enum :

public enum SourceScope
{
National,
Regional
}

finally the Class :

public abstract class Source
{
public virtual SourceScope Scope { get; set; }
}


What is wrong with my mapping ? I have imported a reference to
NHibernate in my project and the EnumStringType exists.

Also I have another question. Supposing it work, how would NH persist
the property Scope in the field ScopeID ? Would it be a string or a
int ? (I'd like it to be a int, not a string).

Thanks !

Paulo Quicoli

unread,
May 20, 2009, 12:10:08 PM5/20/09
to nhu...@googlegroups.com
i use enums.... for that, i map like:

<property name="Scope" column="ScopeID" />

so, i let NHibernate find out the type...



2009/5/20 graphicsxp <graph...@googlemail.com>



--
Paulo R. Quicoli

Editor Técnico - ClubeDelphi Magazine - DevMedia

Tuna Toksoz

unread,
May 20, 2009, 4:17:05 PM5/20/09
to nhu...@googlegroups.com
IF you use EnumString then it will be a string(nvarchar) in database, otherwise it will use int as enum.

Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike

graphicsxp

unread,
May 21, 2009, 3:58:55 AM5/21/09
to nhusers
I see ! So I was making thing more complicated....

Out of interest, do you know what the error I get means ? I won't keep
that code and I will let NH find the type by itself, but I just
wondered what was wrong in my mapping.

Thanks to both of you

On 20 mai, 21:17, Tuna Toksoz <tehl...@gmail.com> wrote:
> IF you use EnumString then it will be a string(nvarchar) in database,
> otherwise it will use int as enum.
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike

Tuna Toksoz

unread,
May 21, 2009, 4:07:01 AM5/21/09
to nhu...@googlegroups.com
Have no idea, a test case would help us (to debug)


Tuna Toksöz
Eternal sunshine of the open source mind.

Reply all
Reply to author
Forward
0 new messages