私は NHibernate でグローバル フィルターを使用しようとしています。私が知る限り、すべてのチュートリアルとまったく同じことを行っていますが、例外が発生しています。
私の .hbm.xml ファイルには次のものが含まれています。
...
<class name="NHibernateSandbox.Foo, NHibernateSandbox" table="Foo">
...
<property column="Content" type="String" name="Content" not-null="true" length="100" />
<property column="Deleted" type="Boolean" name="Deleted" not-null="true" />
<filter name="Foo_Nondeleted" condition="Deleted = false" />
</class>
次に、簡単なテスト クラスがあります。
Configuration cfg = new Configuration();
cfg.Configure();
using (ISessionFactory sf = cfg.BuildSessionFactory()) {
using (ISession session = sf.OpenSession()) {
session.EnableFilter("Foo_Nondeleted");
IQuery query = session.CreateQuery("FROM NHibernateSandbox.Foo");
foreach (Foo foo in query.List<Foo>()) {
Console.WriteLine(foo.Content);
}
}
}
行を削除するEnableFilter
と、期待どおりに機能します。削除された行と削除されていない行の両方が出力されます。ただし、次のEnableFilter
行で NHibernateException が発生します
No such filter configured [Foo_Nondeleted]
at NHibernate.Impl.SessionFactoryImpl.GetFilterDefinition(String filterName)
at NHibernate.Impl.SessionImpl.EnableFilter(String filterName)
at NHibernateSandbox.Program.Main(String[] args)
log4net を詳細に設定すると、
INFO NHibernate.Cfg.HbmBinder - Mapping class: NHibernateSandbox.Foo -> Foo
DEBUG NHibernate.Cfg.HbmBinder - Mapped property: Id -> RID, type: Int32
DEBUG NHibernate.Cfg.HbmBinder - Mapped property: Content -> Content, type: String
DEBUG NHibernate.Cfg.HbmBinder - Mapped property: Deleted -> Deleted, type: Boolean
DEBUG NHibernate.Cfg.HbmBinder - Applying filter [Foo_Nondeleted] as [Deleted = false]
「フィルターの適用」と「構成」されてセッションで使用できるフィルターとの間に欠けているステップは何ですか?