[旗]Nhibernate的的ICriteria枚舉標誌(位掩碼)支持
public enum ShowProductOn : short
{
HomePage = 1,
SalesPage = 2,
NewsLetter = 4
};
此枚舉有效值:
1 - 首頁
2 - SalesPage
3 - 首頁,SalesPage
4 - NewsLetter
5 - 首頁,新聞報
6 - SalesPage,專刊
7 - 首頁,SalesPage,專刊
我想編寫一個返回所有的產品在首頁的標準。 要檢查它在C#中是非常簡單的:
IF((MY_PARAM & ShowProductOn.HomePage)== ShowProductOn.HomePage)
Console.WriteLine("Yes");
在SQL它也很簡單:
DECLARE @BitMask INT = 3
IF((@BitMask & 1)= 1)
BEGIN
Print('Yes')
END
這是NH標準,我寫回所有產品上的主頁(應該匹配1 | 3 | 5 | 7):
的ICriteria標準= NHibernateSession.CreateCriteria() .Add(Restrictions.Eq(「ShowProductOn」,ShowProductOn.HomePage));
此條件僅返回「ShowProductOn」= 1的項目,但忽略其他與「ShowProductOn」= 3 | 5 | 7匹配的項目。
有沒有人知道ICriteria/HQL語法來編寫一個條件,將返回所有項目與「ShowProductOn」= 1 | 3 | 5 | 7?
謝謝。