By default the behaviour of FNH is to map enums to its string in the db.
但是,当将枚举映射为复合键的一部分时,该属性将被映射为int。
例如
在这种情况下
public class Address : Entity
{
public Address() { }
public virtual AddressType Type { get; set; }
public virtual User User { get; set; }
其中addrestype为
public enum AddressType
{
PRESENT, COMPANY, PERMANENT
}
fnh映射是
mapping.CompositeId().KeyReference(x => x.User, "user_id").KeyProperty(x => x.Type);
此映射的架构创建导致
create table address (
Type INTEGER not null,
user_id VARCHAR(25) not null,
和HBM AS
<composite-id mapped="true" unsaved-value="undefined">
<key-property name="Type" type="Company.Core.AddressType, Company.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Type" />
</key-property>
<key-many-to-one name="User" class="Company.Core.CompanyUser, Company.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="user_id" />
</key-many-to-one>
</composite-id>
其中,AddressType应生成为
type="FluentNHibernate.Mapping.GenericEnumMapper`1[[Company.Core.AddressType,
如何指示fnh将其映射为默认的字符串枚举通用映射器?