title: Fluent NHibernat - Querying enum field with LINQ
body: <p>My application has the following database structure:</p>
  
  <pre><code>Transactions:
  - TransactionID (PK, Identity, Int)
  - TypeID (FK, Int)
  - Amount (Decimal)
  
  TransactionTypes:
  - TypeID (PK, Identity, Int)
  - Type (NVarChar)
  </code></pre>
  
  <p>They are defined in my application as:</p>
  
  <pre><code>public class Transaction
  {
      public virtual int TransactionID { get; set; }
      public virtual TransactionTypes Type { get; set; }
      public virtual decimal Amount { get; set; }
  }
  
  public enum TransactionTypes
  {
      Event = 1,
      Product = 2
  }
  </code></pre>
  
  <p>With the following mapping:</p>
  
  <pre><code>public class TransactionMap : ClassMap&lt;Transaction&gt;
  {
      public TransactionMap()
      {
          Table("Transactions");
          Id(x =&gt; x.TransactionID);
          Map(x =&gt; x.Type, "TypeID").CustomType&lt;int&gt;();
          Map(x =&gt; x.Amount);
      }
  }
  </code></pre>
  
  <p>Everything works fine apart from querying.  When i try doing:</p>
  
  <pre><code>session.Linq&lt;Transaction&gt;().Where(t =&gt; t.Type == TransactionTypes.Event).ToList();
  </code></pre>
  
  <p>It throws the error "Type mismatch in <code>NHibernate.Criterion.SimpleExpression</code>: Type expected type <code>System.Int32</code>, actual type <code>Entities.TransactionTypes</code>".</p>
  
  <p>I'd appreciate it if someone could show me the correct way to map this.  Thanks</p>