title: Nhibernate: invoke stored procedure with CreateSqlQuery using already defined mapping
body: <p>I Invoke a stored procedure using <code>ISession.CreateSQLQuery</code>.</p>
  
  <p>Then I use </p>
  
  <pre><code>SetResultTransformer(new AliasToBeanResultTransformer(typeof(Article))).List&lt;Article&gt;().ToList()
  </code></pre>
  
  <p>The problem with this approach is that the <code>AliasToBeanResultTransformer</code> only maps the <code>Article</code> table to the <code>Article</code> class one to one. </p>
  
  <pre><code>public class Article : Entity
  {
      public virtual string Description { get; set; }
  }
  
  public class Entity
  {
      public virtual int Id { get; set; }
  }
  
  public class ArticleRepository : Repository&lt;Article&gt;, IArticleRepository
  {
      private ISession _session;
  
      public ArticleRepository(ISession session) : base(session)
      {
          _session = session;
      }
  
      public List&lt;Article&gt; GetByDescription(string description)
      {
          return _session
              .CreateSQLQuery("EXEC ArticlesByDescription :Description")
              .SetString("Description", description)
              .SetResultTransformer(new AliasToBeanResultTransformer(typeof(Article)))
              .List&lt;Article&gt;().ToList();
      }
  }
  </code></pre>
  
  <p>But my primary key on my <code>Article</code> table is called <code>ArticleId</code>, so that the <code>AliasToBeanResultTransformer</code> throws an exception.</p>
  
  <blockquote>
    <p>Could not find a setter for property 'ArticleId' in class
    'Core.DomainModels.Article'</p>
  </blockquote>
  
  <p>Is there a way of reusing the FluentNhibernateMapping when using <code>CreateSqlQuery</code>?</p>
  
  <p>EDIT:</p>
  
  <p>The <a href="http://nhforge.org/blogs/nhibernate/archive/2008/11/23/populating-entities-from-stored-procedures-with-nhibernate.aspx" rel="nofollow">Nhibernate Documentation</a> describes how you can use an already mapped entity with hbm files.</p>
  
  <pre><code>&lt;sql-query name="GetProductsByCategoryId"&gt;
     &lt;return class="Product" /&gt;
     exec dbo.GetProductsByCategoryId :CategoryId
  &lt;/sql-query&gt;
  </code></pre>
  
  <p>I really ask myself why is it not possible to do this just by code?!</p>