title: How to "Select" with nhibernate queryover
body: <p>I want to use query over to give me back an object</p>
  
  <pre><code> public class TaskMap : ClassMap&lt;Task&gt;
      {
          public TaskMap()
          {
              Table("Tasks");
              Id(x =&gt; x.TaskId);
              Map(x =&gt; x.TaskName).NvarcharWithMaxSize().Not.Nullable();
              Map(x =&gt; x.Description).NvarcharWithMaxSize();
              Map(x =&gt; x.DueDate).Not.Nullable();
              HasMany(x =&gt; x.PersonalTaskReminders).Inverse();
              HasMany(x =&gt; x.TaskReminders).Inverse();
              References(x =&gt; x.Course).Not.Nullable();
              HasMany(x =&gt; x.CompletedTasks);
  
          }
      }
  
  
  
  [Serializable()]
  public class Task
  {
      public virtual int TaskId { get; private set; }
      public virtual string TaskName { get;  set; }
      public virtual string Description { get; set; }
      public virtual DateTime DueDate { get; set; }
      public virtual IList&lt;PersonalTaskReminder&gt; PersonalTaskReminders { get; set; }
      public virtual IList&lt;TaskReminder&gt; TaskReminders { get; set; }
      public virtual IList&lt;CompletedTask&gt; CompletedTasks { get; set; }
      public virtual Course Course { get; set; }
  
      public Task()
      {
          PersonalTaskReminders = new List&lt;PersonalTaskReminder&gt;();
          TaskReminders = new List&lt;TaskReminder&gt;();
          CompletedTasks = new List&lt;CompletedTask&gt;();
      }
  
  }
       public class PlannerTask
  {
      public int TaskId { get; set; }
      public string TaskName { get; set; }
      public string Description { get; set; }
      public DateTime DueDate { get; set; }
      public List&lt;PersonalTaskReminder&gt; PersonalTaskReminders { get; set; }
      public List&lt;TaskReminder&gt; TaskReminders { get; set; }
      public Course Course { get; set; }
      public bool IsCompleted { get; set; }
  
  
  }
  </code></pre>
  
  <p><strong>Try 1</strong></p>
  
  <pre><code>Task tAlias = null;
          PlannerTask plannerTask = null;
          List&lt;PlannerTask&gt; result = session.QueryOver&lt;Task&gt;(() =&gt; tAlias)
              .Select(x =&gt; x.Course).TransformUsing(Transformers.AliasToBean&lt;PlannerTask&gt;())               
              .List&lt;PlannerTask&gt;().ToList();
  </code></pre>
  
  <p>result: 188 records with all null for course object.</p>
  
  <p><strong>Try 2</strong></p>
  
  <pre><code>Task tAlias = null;
              PlannerTask plannerTask = null;
              List&lt;PlannerTask&gt; result = session.QueryOver&lt;Task&gt;(() =&gt; tAlias)
                           .Select(Projections.Property(() =&gt; tAlias.TaskId).WithAlias(() =&gt; plannerTask.TaskId),
                           Projections.Property(() =&gt; tAlias.TaskName).WithAlias(() =&gt; plannerTask.TaskName),
                           Projections.Property(() =&gt; tAlias.DueDate).WithAlias(() =&gt; plannerTask.DueDate),
                           Projections.Property(() =&gt; tAlias.Description).WithAlias(() =&gt; plannerTask.Description),
                           Projections.Property(() =&gt; tAlias.PersonalTaskReminders).WithAlias(() =&gt; plannerTask.PersonalTaskReminders),
                           Projections.Property(() =&gt; tAlias.TaskReminders).WithAlias(() =&gt; plannerTask.PersonalTaskReminders),
                           Projections.Property(() =&gt; tAlias.Course).WithAlias(() =&gt; plannerTask.Course))
                  .TransformUsing(Transformers.AliasToBean&lt;PlannerTask&gt;())               
                  .List&lt;PlannerTask&gt;().ToList();
  </code></pre>
  
  <p>Result: 188 courses with all properties having pretty much the same error</p>
  
  <pre><code>'((new System.Collections.Generic.Mscorlib_CollectionDebugView&lt;Domain.PlannerTask&gt;(result)).Items[0].Course).CoursePermissions' threw an exception of type 'NHibernate.ObjectNotFoundException'
  </code></pre>
  
  <p><strong>Try 3</strong></p>
  
  <pre><code> Task tAlias = null;
          PlannerTask plannerTask = null;
          List&lt;PlannerTask&gt; result = session.QueryOver&lt;Task&gt;(() =&gt; tAlias)
               .Select(Projections.Property(() =&gt; tAlias.TaskId).WithAlias(() =&gt; plannerTask.TaskId),
               Projections.Property(() =&gt; tAlias.TaskName).WithAlias(() =&gt; plannerTask.TaskName),
               Projections.Property(() =&gt; tAlias.DueDate).WithAlias(() =&gt; plannerTask.DueDate),
               Projections.Property(() =&gt; tAlias.Description).WithAlias(() =&gt; plannerTask.Description),
               Projections.ProjectionList().Add(Projections.Property(()=&gt; tAlias.PersonalTaskReminders).WithAlias(() =&gt; plannerTask.PersonalTaskReminders)),
               Projections.ProjectionList().Add(Projections.Property(()=&gt; tAlias.TaskReminders).WithAlias(() =&gt; plannerTask.PersonalTaskReminders)),
               Projections.Property(() =&gt; tAlias.Course).WithAlias(() =&gt; plannerTask.Course))
              .TransformUsing(Transformers.AliasToBean&lt;PlannerTask&gt;())               
              .List&lt;PlannerTask&gt;().ToList();
  
  
  SELECT this_.TaskId      as y0_,
         this_.TaskName    as y1_,
         this_.DueDate     as y2_,
         this_.Description as y3_,
         this_.TaskId      as y4_,
         this_.TaskId      as y4_,
         this_.CourseId    as y4_
  FROM   Tasks this_
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>CoursePermissions = '((Castle.Proxies.CourseProxy)((new System.Collections.Generic.Mscorlib_CollectionDebugView&lt;PlannerTask&gt;(result)).Items[0].Course)).CoursePermissions' threw an exception of type 'NHibernate.ObjectNotFoundException'
  </code></pre>
  
  <p><strong>try 4</strong></p>
  
  <p>Try 4</p>
  
  <pre><code> Task tAlias = null;
          PlannerTask plannerTask = null;
          List&lt;PlannerTask&gt; result = session.QueryOver&lt;Task&gt;(() =&gt; tAlias)
               .Select(Projections.Property(() =&gt; tAlias.TaskId).WithAlias(() =&gt; plannerTask.TaskId),
               Projections.Property(() =&gt; tAlias.TaskName).WithAlias(() =&gt; plannerTask.TaskName),
               Projections.Property(() =&gt; tAlias.DueDate).WithAlias(() =&gt; plannerTask.DueDate),
               Projections.Property(() =&gt; tAlias.Description).WithAlias(() =&gt; plannerTask.Description),
               Projections.Property(() =&gt; tAlias.Course).WithAlias(() =&gt; plannerTask.Course))
              .TransformUsing(Transformers.AliasToBean&lt;PlannerTask&gt;())               
              .List&lt;PlannerTask&gt;().ToList();
  
  
  SELECT this_.TaskId      as y0_,
         this_.TaskName    as y1_,
         this_.DueDate     as y2_,
         this_.Description as y3_,
         this_.CourseId    as y4_
  FROM   Tasks this_
  </code></pre>
  
  <p>Works. I can access everything in the course object.</p>
  
  <p>It seems to have a problem with </p>
  
  <p>tAlias.PersonalTaskReminders and tAlias.TaskReminders. If I remove these Course will render fine.</p>
  
  <p>I don't understand why.</p>