如果您從源代碼構建Fluent,現在支持過濾器。您可以使用它們像這樣:
首先創建一個類從FluentNHibernate.Mapping.FilterDefinition
繼承:
using FluentNHibernate.Mapping;
namespace PonyApp.FluentFilters
{
public class PonyConditionFilter : FilterDefinition
{
public PonyConditionFilter()
{
WithName("PonyConditionFilter")
.AddParameter("condition",NHibernate.NHibernateUtil.String);
}
}
}
在你的類映射爲您的類,使用確定applyFilter方法:
namespace PonyApp.Entities.Mappings
{
public class PonyMap : ClassMap<Pony>
{
public PonyMap()
{
Id(x => x.Id);
Map(x => x.PonyName);
Map(x => x.PonyColor);
Map(x => x.PonyCondition);
ApplyFilter<PonyConditionFilter>("PonyCondition = :condition");
}
}
}
然後將過濾器添加到您的流利的配置:
Fluently.Configure()
.Mappings(m => m.FluentMappings.Add(typeof(PonyConditionFilter)))
//blah blah bunches of other important stuff left out
.BuildSessionFactory();
然後你可以打開它就像你用香草NHibernate一樣:
session.EnableFilter("PonyConditionFilter").SetParameter("condition","Wonderful");
Downvoted,因爲在回答時不支持的功能後來被支持了嗎?這太苛刻了。 – 2013-04-18 13:18:17
我同意downvote是苛刻的,但你仍然可能想更新你的答案,注意框架的當前狀態。 – 2014-07-03 15:22:26