title: How can the NamedSQLQueryDefinition class be used dynamically as a sql-query equivalent?
body: <p>I need to dynamically add named queries to the NHibernate configuration object. The search engines return few hits referencing NamedSQLQueryDefinition or NamedQueryDefinition. Below is what I'm attempting to do. I don't know what to provide to the NamedSQLQueryDefinition constructor to successfully create a query. Can anyone provide a sample of how to create a new NamedSQLQueryDefinition the right way? Thanks!!</p>
  
  <p>Session initializer:</p>
  
  <pre><code>    private static ISessionFactory CreateSessionFactory()
      {
          var configuration = new Configuration();
  
          return Fluently.Configure(configuration.Configure())
              .ExposeConfiguration(AddQueries)
              .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;Program&gt;())
              .Mappings(m =&gt; m.HbmMappings.AddFromAssemblyOf&lt;Program&gt;())
              .BuildConfiguration()
              .BuildSessionFactory();
      }
  </code></pre>
  
  <p>The AddQueries would look something like this:</p>
  
  <pre><code>    private static void AddQueries(Configuration cfg)
      {
          var nameQuery = new NamedSQLQueryDefinition("exec pr_GETCustomer ?", ...)
  
          cfg.NamedSQLQueries.Add("pr_GETCustomer", nameQuery);
          var cust = cfg.GetClassMapping(typeof (Customer));
  
          cust.LoaderName = "pr_GETCustomer";
      }
  </code></pre>
  
  <p>PS: I'm trying this route because Fluent NHibernate does not implement a way to configuring the loader &amp; sql-query elements from the hbm file.</p>