質問は本当にすべてを言います、デフォルトはそれがaとしてマップすることですがstring、私はとしてマップする必要がありintます。
私は現在PersistenceModel、それが何らかの違いを生む場合、私の慣習を設定するために使用しています。前もって感謝します。
更新 トランクから最新バージョンのコードにアクセスすると、私の問題が解決したことがわかりました。
質問は本当にすべてを言います、デフォルトはそれがaとしてマップすることですがstring、私はとしてマップする必要がありintます。
私は現在PersistenceModel、それが何らかの違いを生む場合、私の慣習を設定するために使用しています。前もって感謝します。
更新 トランクから最新バージョンのコードにアクセスすると、私の問題が解決したことがわかりました。
回答:
この規約を定義する方法は以前に変更されましたが、現在は次のようになっています。
public class EnumConvention : IUserTypeConvention
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType.IsEnum);
    }
    public void Apply(IPropertyInstance target)
    {
        target.CustomType(target.Property.PropertyType);
    }
}したがって、前述のように、最新バージョンのFluent NHibernateをトランクから外すことで、必要な場所に移動できました。最新のコードを使用した列挙型のマッピングの例は次のとおりです。
Map(quote => quote.Status).CustomTypeIs(typeof(QuoteStatus));カスタムタイプは、を使用するのではなく、列挙型のインスタンスとして処理するように強制しますGenericEnumMapper<TEnum>。
文字列を永続化する列挙型マッパーとintを永続化するものの間で変更できるようにパッチを提出することを実際に検討しています。
これは私の最近の活動に現れ、Fluent NHibernateの新しいバージョンではこれが簡単になるように変更されました。
すべての列挙型を整数としてマッピングするには、次のような規則を作成します。
public class EnumConvention : IUserTypeConvention
{
    public bool Accept(IProperty target)
    {
        return target.PropertyType.IsEnum;
    }
    public void Apply(IProperty target)
    {
        target.CustomTypeIs(target.PropertyType);
    }
    public bool Accept(Type type)
    {
        return type.IsEnum;
    }
}次に、マッピングは次のようにするだけです:
Map(quote => quote.Status);このように、Fluent NHibernateマッピングに規則を追加します。
Fluently.Configure(nHibConfig)
    .Mappings(mappingConfiguration =>
    {
        mappingConfiguration.FluentMappings
            .ConventionDiscovery.AddFromAssemblyOf<EnumConvention>();
    })
    ./* other configuration */null許容列挙型(などExampleEnum? ExampleProperty)を忘れないでください!個別に確認する必要があります。これは、新しいFNHスタイルの構成でどのように行われるかです。
public class EnumConvention : IUserTypeConvention
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType.IsEnum ||
            (x.Property.PropertyType.IsGenericType && 
             x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
             x.Property.PropertyType.GetGenericArguments()[0].IsEnum)
            );
    }
    public void Apply(IPropertyInstance target)
    {
        target.CustomType(target.Property.PropertyType);
    }
}int?そして、型がフラグを受け入れるとき?例:MyEnum.Active | MyEnum.Paused
                    これは、列挙型プロパティをint値にマッピングする方法です。
Map(x => x.Status).CustomType(typeof(Int32));私のために働く!
自動マッピングでFluent NHibernateを使用している場合(および潜在的にIoCコンテナー):
これIUserTypeConventionは上記の@ Julienの回答と同じです:https : //stackoverflow.com/a/1706462/878612
public class EnumConvention : IUserTypeConvention
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType.IsEnum);
    }
    public void Apply(IPropertyInstance target)
    {
        target.CustomType(target.Property.PropertyType);
    }
}Fluent NHibernate Automapping構成は次のように構成できます。
    protected virtual ISessionFactory CreateSessionFactory()
    {
        return Fluently.Configure()
            .Database(SetupDatabase)
            .Mappings(mappingConfiguration =>
                {
                    mappingConfiguration.AutoMappings
                        .Add(CreateAutomappings);
                }
            ).BuildSessionFactory();
    }
    protected virtual IPersistenceConfigurer SetupDatabase()
    {
        return MsSqlConfiguration.MsSql2008.UseOuterJoin()
        .ConnectionString(x => 
             x.FromConnectionStringWithKey("AppDatabase")) // In Web.config
        .ShowSql();
    }
    protected static AutoPersistenceModel CreateAutomappings()
    {
        return AutoMap.AssemblyOf<ClassInAnAssemblyToBeMapped>(
            new EntityAutomapConfiguration())
            .Conventions.Setup(c =>
                {
                    // Other IUserTypeConvention classes here
                    c.Add<EnumConvention>();
                });
    }*次に、CreateSessionFactoryCastle WindsorなどのIoC(PersistenceFacilityとインストーラーを使用)で簡単に使用できます。*
    Kernel.Register(
        Component.For<ISessionFactory>()
            .UsingFactoryMethod(() => CreateSessionFactory()),
            Component.For<ISession>()
            .UsingFactoryMethod(k => k.Resolve<ISessionFactory>().OpenSession())
            .LifestylePerWebRequest() 
    );NHibernateを作成し、プロパティマップでIUserType指定することができますCustomTypeIs<T>()。
DBテーブルに値をint / tinyintとして保持する必要があります。enumをマッピングするには、マッピングを正しく指定する必要があります。以下のマッピングと列挙型のサンプルを参照してください。
マッピングクラス
パブリッククラスTransactionMap:ClassMap Transaction
{
    public TransactionMap()
    {
        //その他のマッピング
        .....
        //列挙型のマッピング
        Map(x => x.Status、 "Status")。CustomType();
        Table( "トランザクション");
    }
}
列挙型
パブリック列挙型TransactionStatus
{
   待機中= 1
   処理済み= 2
   RolledBack = 3
   ブロック= 4、
   払い戻し= 5
   AlreadyProcessed = 6
}