title: SelectList in QueryOver
body: <p>I have some problem with selecting by QueryOver, here are my model classes:</p>
  
  <pre><code>public class BaseModel
  {
      public virtual int Id { get; set; }
      public virtual DateTime ModifyDate { get; set; }
      public virtual DateTime CreateDate { get; set; }
      public virtual User CreateUser { get; set; }
      public virtual User ModifyUser { get; set; }
      public virtual bool IsActive { get; set; }
  }
  
  public class BaseClassMap&lt;T&gt; : ClassMap&lt;T&gt; where T : BaseModel
  {
      public BaseClassMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Identity();
          References(x =&gt; x.CreateUser, "CreateUser_Id");
          References(x =&gt; x.ModifyUser, "ModifyUser_Id");
          Map(x =&gt; x.CreateDate).Not.Nullable().Default("GETDATE()");
          Map(x =&gt; x.ModifyDate).Not.Nullable().Default("GETDATE()"); ;
          Map(x =&gt; x.IsActive).Not.Nullable().Default("1");
      }
  }
  
  public class Expenditure : BaseModel
  {
      public virtual decimal Amount { get; set; }
      public virtual Category Category { get; set; }
      public virtual string Comment { get; set; }
      public virtual DateTime Month { get; set; }
  }
  
  public class ExpenditureMap : BaseClassMap&lt;Expenditure&gt;
  {
      public ExpenditureMap()
      {
          Schema("[budget]");
          Table("[Expenditure]");
          Id(x =&gt; x.Id);
          Map(x =&gt; x.Amount).Not.Nullable(); 
          Map(x =&gt; x.Comment);
          Map(x =&gt; x.Month).Not.Nullable(); 
          References(x =&gt; x.Category, "Category_Id").Not.Nullable();
      }
  }
  
  public class User : BaseModel
  {
      public virtual string Login { get; set; }
      public virtual string Email { get; set; }
      public virtual string Password { get; set; }
      public virtual string PasswordSalt { get; set; }
      public virtual string HashAlgorithm { get; set; }
  }
  
  public class UserMap : BaseClassMap&lt;User&gt;
  {
      public UserMap()
      {
          Schema("[permission]");
          Table("[User]");
          Id(x =&gt; x.Id);
          Map(x =&gt; x.Login).Not.Nullable(); 
          Map(x =&gt; x.Email).Not.Nullable();
          Map(x =&gt; x.Password).Not.Nullable();
          Map(x =&gt; x.PasswordSalt);
          Map(x =&gt; x.HashAlgorithm).Not.Nullable();
      }
  }
  
  public class ExpenseDetailsItemVm
  {
      public int Id { get; set; }
      public string Comment { get; set; }
      public decimal Amount { get; set; }
      public DateTime CreateDate { get; set; }
      public string CreateUser { get; set; }
  }
  </code></pre>
  
  <p>And here is my query:</p>
  
  <pre><code>var user = new User();
  var result = new ExpenseDetailsItemVm();
  var expenses = SessionManager.Session.QueryOver&lt;Expenditure&gt;()
                               .JoinAlias(x =&gt; x.CreateUser, () =&gt; user)
                               .Where(x =&gt; x.IsActive &amp;&amp;  
                                           x.Category.Id == categoryId &amp;&amp; 
                                           x.Month == date.ToFirstDayOfMonth())
                               .SelectList(list =&gt; list
                                                .Select(x =&gt; x.Id).WithAlias(() =&gt; result.Id)
                                                .Select(x =&gt; x.Amount).WithAlias(() =&gt; result.Amount)
                                                .Select(x =&gt; x.Comment).WithAlias(() =&gt; result.Comment)
                                                .Select(x =&gt; x.CreateDate).WithAlias(() =&gt; result.CreateDate)
                                                .Select(()=&gt; user.Login).WithAlias(() =&gt; result.CreateUser)
              ).TransformUsing(Transformers.AliasToBean&lt;ExpenseDetailsItemVm&gt;())
              .List&lt;ExpenseDetailsItemVm&gt;();
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>I'm sure the problem on this line of code:</p>
  
  <pre><code> .Select(()=&gt; user.Login).WithAlias(() =&gt; result.CreateUser)
  </code></pre>
  
  <p>If I comment this line out, the query works fine and return result without error.</p>
  
  <p>To eliminate mapping mistake, I tried this:</p>
  
  <pre><code>var u = SessionManager.Session.QueryOver&lt;User&gt;().Where(x =&gt; x.Id == 1).
              SelectList(list =&gt; list.
                  Select(x =&gt; x.Login).WithAlias(() =&gt; result.CreateUser))
              .TransformUsing(Transformers.AliasToBean&lt;ExpenseDetailsItemVm&gt;())
              .List&lt;ExpenseDetailsItemVm&gt;();
  </code></pre>
  
  <p>And this also works fine.</p>
  
  <p>In my <code>Expenditure</code> table, the column <code>CreateUser_Id</code> everywhere has a value</p>