title: Is there any consideration while comparing Enums in LINQ-to-NHibernate or LINQ?
body: <p>In such a query:</p>
  
  <pre><code>var q = from l in session.Linq&lt;Letter&gt;()
      where
      letterTypeSearch == null ? true : 
          (l.LetterType.ToString() == letterTypeSearch)
  </code></pre>
  
  <p>l.LetterType is an Enum.</p>
  
  <p><strong>UPDATE</strong>
  It seems that's impossible to compare Enums in current linq-to-nhibernate. While letterTypeSearch is a string containing a <code>LetterType</code> instance that is <code>ToString()</code>ed and <code>LetterType</code> is inherited from <code>int</code>, there 3 ways of comparisons:</p>
  
  <p>1- Comparing in <code>String</code>: It impossible because <code>l.LetterType.ToString()</code> produces "(ArgumentOutOfRangeException): Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index, " error.</p>
  
  <p>2- Comparing in <code>Enum</code> (<code>LetterType</code>) itself: It is impossible too because <code>l.LetterType == LetterType.Internal</code> results in "(QueryException): Type mismatch in NHibernate.Criterion.SimpleExpression: LetterType expected type System.Int32, actual type Faraconesh.EnterpriseAppUnits.OfficeAutomation.BusinessEntities.LetterType, 
  " error.</p>
  
  <p>3- Comparing in <code>Int32</code>: Yet not possible, because <code>Convert.ToInt32(l.LetterType)</code> generates "(NotImplementedException): The method ToInt32 is not implemented., " error.</p>
  
  <p>So how can I compare Enums in LINQ-to-NHibernate? Is this problem specific to LINQ-to-NHibernate or all LINQ users have such a problem?</p>
  
  <p><strong>UPDATE2</strong>
  here are class, enum and mapping (smmarized):</p>
  
  <pre><code>    public class Letter
      {
          private LetterType _letterType;
          public LetterType LetterType
          {
              set
              {
                  _letterType = value;
              }//end  
              get
              {
                  return _letterType;
              }//end  
          }
  }
  </code></pre>
  
  <p>=========</p>
  
  <p>public enum LetterType
  {
      Incoming = 0,
      Outgoing = 1,
      Internal = 2,
  }</p>
  
  <p>=========</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"&gt;
    &lt;class
         name="Faraconesh.EnterpriseAppUnits.OfficeAutomation.BusinessEntities.Letter,Faraconesh.EnterpriseAppUnits.OfficeAutomation.BusinessEntities"
          table="OfficeAutomation_Letter"&gt;
  
      &lt;property
           name="LetterType" column="LetterType"
           type="int" update="true" insert="true" access="property"
           not-null="true"/&gt;
  
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>