2

默认情况下,FNH 的行为是将枚举映射到其在数据库中的字符串。

但是在将枚举映射为复合键的一部分时,该属性被映射为 int。
例如
在这种情况下

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

地址类型在哪里

  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 作为

<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 将 mappit 作为默认字符串枚举通用映射器?

4

1 回答 1

0

詹姆斯回应了答案。

于 2010-03-25T06:22:56.873 回答