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