Take the following Enum Flag
[Flags]
enum Permssions
{
CanComment = 1,
CanEdit = 2,
CanDelete = 4,
CanRemoveUsers = 8,
All = CanComment | CanE
When I map an enum, and this enum has a backing value of type 'int', I just map my enum property to an int field in the database. I haven't run into problems for this.
I have done this for flag enums as well, and this just works without problems.
When you combine certain flags, NHibernate will persist the 'combination' of those flags into the specified column in the database.
When you retrieve the instance that has a property of 'flag enums', then NHibernate will reconstitute it back to the correct combination.
For instance, if the DB contains '3', then NHibernate will populate your property with the combination of the apropriate values.
In fact, I let NHibernate figure it out all by himself:
where the OnCallType column is of type int in my DB, and the OnCallType property is an enumerated type that has the flags attribute.