title: Nhibernate query entity with enum property
body: <p>I need to query the entity <code>Person</code> with enum property <code>TargetBookingSystemType</code></p>
  
  <pre><code>public class Person : EntityWithTypedId&lt;PersonCompositeId&gt;
  {
      public virtual string Key { get; set; }
  
      public virtual TargetBookingSystemType TargetBookingSystemType { get; set; }
  }
  
  
   public class PersonMap : ClassMap&lt;Person&gt;
   {
       public PersonMap()
       {
          this.CompositeId(x =&gt; x.Id).KeyProperty(y =&gt; y.AccountName, "[AccountName]").KeyProperty(y =&gt; y.Domain, "[Domain]");
          this.Table("Person");
          this.Map(x =&gt; x.Key).Column("[Key]");
          this.Map(x =&gt; x.TargetBookingSystemType).Column("[TargetBookingSystemType]");//.CustomType&lt;TargetBookingSystemType&gt;();
       }
   }
  
  public enum TargetBookingSystemType
      {
          GoogleCalendarAPIv3 = 1,
          MSExchange2007 = 2,
          MSExchange2010 = 3,
          MSExchange2013 = 4,
          MSOnline = 5
      }
  
  CREATE TABLE [dbo].[Person](
      [Domain] [varchar](3) NOT NULL,
      [AccountName] [varchar](255) NOT NULL,
      [Key] [varchar](255) NOT NULL,
      [TargetBookingSystemType] [nvarchar](20) NULL
   )
  </code></pre>
  
  <p>I know that a possible solution is to change the type of the property to string but how can I achieve that using NHibernate I can have the property as an enum and still get a successful query?</p>
  
  <p>Tried CustomType() but with no luck getting an error <code>Input string was not in a correct format.</code></p>
  
  <p>please note that the query is working when I comment out the line with mapping of <code>TargetBookingSystemType</code></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I would like to have one call to DB and after that filtering the result based on the enum.
  This is the method doing the query using NHibernate:</p>
  
  <pre><code>public IList&lt;Domain.DomainObjects.Entities.Person&gt; GetAllPersons()
          {
              IList&lt;Domain.DomainObjects.Entities.Person&gt; list = new List&lt;Domain.DomainObjects.Entities.Person&gt;();
              string queryString = "select MR from Person MR";
              return this.Session.CreateQuery(queryString).SetCacheable(true).SetCacheRegion("LongTerm").List&lt;Domain.DomainObjects.Entities.Person&gt;();
          }
  </code></pre>
  
  <p>How can I get the enum property in the result aswell? </p>