Hi I've got this enum:
[Flags]
public enum ShowProductOn : short
{
HomePage = 1,
SalesPage = 2,
NewsLetter = 4
};
Valid values for this enum:
1 - HomePage
2 - SalesPage
3 - HomePage, SalesPage
4 - NewsLetter
5 - HomePage, NewsLetter
6 - SalesPage, NewsLetter
7 - HomePage, SalesPage, NewsLetter
I would like to write a criteria that returns all the products on homepage. To check it in c# is very simple:
if ((MY_PARAM & ShowProductOn.HomePage) == ShowProductOn.HomePage)
Console.WriteLine("Yes");
in Sql it's also very simple:
DECLARE @BitMask int = 3
IF ((@BitMask & 1) = 1)
BEGIN
Print('Yes')
END
This is the NH Criteria that I wrote to return all products on homepage (should match 1|3|5|7):
ICriteria criteria = NHibernateSession.CreateCriteria() .Add(Restrictions.Eq("ShowProductOn", ShowProductOn.HomePage));
This criteria returns only items with "ShowProductOn"=1 but ignores the other matched items with "ShowProductOn"=3|5|7.
Does anyone knows the ICriteria /HQL syntax to write a criteria that will return all items with "ShowProductOn"=1|3|5|7 ?
Shay.