I have a class and inside it, a string and a list of enumerators.
public enum SomeEnum
{
Undefined=0,
Enum1,
Enum2,
Enum3,
End
}
public class SomeObject
{
public virtual int ID{get; set;}
public virtual String Name {get; set;}
public virtual IList<SomeEnum> EnumList {get; set;}
}
Now, there should be a list of SomeObjects, containing ID and Name. There should be another map like this:
5 2
5 3
3 1
9 3
Meaning, a player with ID 5 has Enum2 and Enum3, another player with ID 3 has Enum1, and a player with ID 9 has Enum3.
They say it’s possible to map int, float etc. but I don’t want to create IList out of my list.
Is there an easy way to make fluent nhibernate do that?
HasMany(x => x.EnumList )
.Cascade.All()
.Table("ObjectEnumTable");
This mapping file throws an exception and says “Association references unmapped class: SomeEnum”.
Thanks in advance.
You’re better off storing your List of enum values as a straight Flags enum value, but if you absolutely must have a list of enums (you need support for duplicates or legacy database), then your mapping shoud look like this:
The key is the .Element() method which you must have for any non-entity HasMany relationship, including strings, ints, etc. This will give you the ID column referencing your parent entity, and an EnumValueColumn column with your enum value for each item.