简体   繁体   中英

Fluent nhibernate: Enum in composite key gets mapped to int when I need string

By default the behaviour of FNH is to map enums to its string in the db.

But while mapping an enum as part of a composite key, the property gets mapped as int.
eg
in this case

  public class Address : Entity
  {
    public Address() { }
    public virtual AddressType Type { get; set; }
    public virtual User User { get; set; }

Where AddresType is of

  public enum AddressType
  {
    PRESENT, COMPANY, PERMANENT
  }

The FNH mapping is as

 mapping.CompositeId().KeyReference(x => x.User, "user_id").KeyProperty(x => x.Type);

the schema creation of this mapping results in

create table address (
    Type INTEGER not null,
   user_id VARCHAR(25) not null,

and the 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>

Where the AddressType should have be generated as

type="FluentNHibernate.Mapping.GenericEnumMapper`1[[Company.Core.AddressType,

How do I instruct FNH to mappit as the default string enum generic mapper?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM