title: Linq to NHibernate query comparing enum mapped as integer succeeds, but fails as equivalent criteria query
body: <p>I'm querying for ProductRisk, which contains a Status property, where Status is an enum. Here's the mapping for ProductRisk: </p>
  
  <pre><code>public class ProductRiskMap : ClassMap&lt;ProductRisk&gt;
  {
      public ProductRiskMap()
      {
          Table("AccountManagement.dbo.ProductRisk");
  
          Id(x =&gt; x.Id, "ProductRiskID");
  
          References(x =&gt; x.AssociatedProduct, "ProductID");
          References(x =&gt; x.AssociatedClient, "EntityId");
  
          Map(x =&gt; x.Reason, "ProductRiskReasonID").CustomType&lt;int&gt;();
          Map(x =&gt; x.Status, "RiskStatusID").CustomType&lt;int&gt;();
      }
  </code></pre>
  
  <p>Status is an enum with four possible values. It's represented in the database as a foreign key reference to a lookup table. In my repository, I want to pull the ProductRisk objects with a Status of <code>Medium</code> or <code>High</code>. The following query in Ling To NHibernate works: </p>
  
  <pre><code>    public IList&lt;ProductRisk&gt; GetByClient(int[] clientIds)
      {
          return NHibernateSession.Current.Query&lt;ProductRisk&gt;()
              .Where(x =&gt; clientIds.Contains(x.AssociatedClient.Id))
              .Where(x =&gt; x.Status == RiskStatus.Medium || x.Status == RiskStatus.High)                
              .ToList();
      }
  </code></pre>
  
  <p>But if I use (what I think is) the equivalent query in the Criteria API: </p>
  
  <pre><code>        return NHibernateSession.Current.QueryOver&lt;ProductRisk&gt;()
              .WhereRestrictionOn(x =&gt; x.AssociatedClient.Id).IsIn(clientIds)
              .Where(x =&gt; x.Status == RiskStatus.Medium || x.Status == RiskStatus.High)
              .List();
  </code></pre>
  
  <p>I receive the following error: </p>
  
  <blockquote>
    <p>Type mismatch in NHibernate.Criterion.SimpleExpression: Status
    expected type System.Int32, actual type
    FIS.AccountManagement.Core.Domain.RiskStatus</p>
  </blockquote>
  
  <p>Why is that? Thanks in advance for any help. </p>