基準 API を使用してそれを行う方法は次のとおりです。
[Flags]
enum Bar{
A = 0x01,
B = 0x02,
C = 0x04
}
var criteria = this.Session.CreateCriteria<Foo>()
.Add( BitwiseFlags.IsSet( "Bar", Bar.A | Bar.C ) );
使用:
public class BitwiseFlags : LogicalExpression
{
private BitwiseFlags( string propertyName, object value, string op ) :
base( new SimpleExpression( propertyName, value, op ),
Expression.Sql( "?", value, NHibernateUtil.Enum( value.GetType() ) ) )
{
}
protected override string Op
{
get { return "="; }
}
public static BitwiseFlags IsSet(string propertyName, Enum flags)
{
return new BitwiseFlags( propertyName, flags, " & " );
}
}
次の出力 where 句を生成する必要があります。
FROM _TABLE
WHERE (this_.Bar & 5 = 5)
これにより、フラグ Bar.A および Bar.C が設定された行が得られます (他のすべてを除く)。接続詞や選言でも使えるはずです。