title: Property with Formula (generated=always) generates invalid SQL for post-insert Select
body: <p>I'm using NHibernate 2.1CR1. I modified the nhibernate sample from here
  <a href="http://weblogs.asp.net/pwilson/archive/2005/05/26/409042.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/pwilson/archive/2005/05/26/409042.aspx</a> to work
  with the new version</p>
  
  <p>The class</p>
  
  <pre><code>namespace Wilson.NHibernate.Example
  {
         public class Contact
         {
                 private int id; // Database-Generated Key Field
                 private string name;
                 private Address address = new Address(); // Embedded Object Type
                 private IList categories = new ArrayList(); // Many-To-Many
  Relationship
                 private IList details = new ArrayList(); // One-To-Many Relationship
  
         virtual public int Id
         {
                         get { return this.id; }
                 }
  
         virtual public string Name
         {
                         get { return this.name; }
                         set { this.name = value; }
                 }
  
         virtual public Address Address
         {
                         get { return this.address; }
                 }
  
         virtual public IList Categories
         {
                         get { return this.categories; }
                 }
  
         virtual public IList Details
         {
                         get { return this.details; }
                 }
  
                 public override string ToString() {
                         return this.name;
                 }
  
         virtual public string PropertyWithFormula
         {
             get;
             set;
         }
         }
  }
  </code></pre>
  
  <p>Here's the relevant mapping fragment</p>
  
  <pre><code>&lt;class name="Wilson.NHibernate.Example.Contact,
  WilsonNHibernateExample" table="Contacts" discriminator-value="?" &gt;
                 &lt;id name="Id" column="ContactId" access="nosetter.camelcase" unsaved-
  value="0"&gt;
                         &lt;generator class="identity" /&gt;
                 &lt;/id&gt;
                 &lt;discriminator column="ContactType" /&gt;
                 &lt;property name="Name" column="ContactName" /&gt;
                 &lt;component name="Address" class="Wilson.NHibernate.Example.Address,
  WilsonNHibernateExample" access="nosetter.camelcase"&gt;
                         &lt;property name="Line" column="AddressLine" not-null="false" /&gt;
                         &lt;property name="City" column="AddressCity" not-null="false" /&gt;
                         &lt;property name="State" column="AddressState" not-null="false" /&gt;
                         &lt;property name="Zip" column="AddressZip" not-null="false" /&gt;
                 &lt;/component&gt;
  
     &lt;property name="PropertyWithFormula"  formula="('TestFormula')"
  generated="always" /&gt;
  
                 &lt;bag name="Categories" table="CategoryContacts" cascade="none"
  access="nosetter.camelcase" lazy="false" inverse="false"&gt;
                         &lt;key column="ContactId" /&gt;
                         &lt;many-to-many column="CategoryId"
  class="Wilson.NHibernate.Example.Category, WilsonNHibernateExample" /&gt;
                 &lt;/bag&gt;
                 &lt;bag name="Details" cascade="all" access="nosetter.camelcase"
  lazy="false" inverse="true"&gt;
                         &lt;key column="ContactId" /&gt;
                         &lt;one-to-many class="Wilson.NHibernate.Example.Detail,
  WilsonNHibernateExample" /&gt;
                 &lt;/bag&gt;
                 &lt;subclass name="Wilson.NHibernate.Example.Person,
  WilsonNHibernateExample" discriminator-value="P" /&gt;
                 &lt;subclass name="Wilson.NHibernate.Example.Business,
  WilsonNHibernateExample" discriminator-value="B"&gt;
                         &lt;property name="Company" column="CompanyName" /&gt;
                 &lt;/subclass&gt;
         &lt;/class&gt;
  </code></pre>
  
  <p>======================================================</p>
  
  <p>Here are the traces from SQL Server:
  When I call session.Get(1), the sql is correctly generated:
  (''TestFormula'') as formula0_0_</p>
  
  <pre><code>exec sp_executesql N'SELECT contact0_.ContactId as ContactId2_0_,
  contact0_.ContactName as ContactN3_2_0_, contact0_.AddressLine as
  AddressL4_2_0_, contact0_.AddressCity as AddressC5_2_0_,
  contact0_.AddressState as AddressS6_2_0_, contact0_.AddressZip as
  AddressZip2_0_, contact0_.CompanyName as CompanyN8_2_0_,
  (''TestFormula'') as formula0_0_, contact0_.ContactType as
  ContactT2_2_0_ FROM Contacts contact0_ WHERE
  contact0_.ContactId=@p0',N'@p0 int',@p0=1
  </code></pre>
  
  <p>But when I do an insert, which then fires another select to get the
  generated values
  It generates an invalid sql for the same property: contact_. as
  formula0_</p>
  
  <pre><code>exec sp_executesql N'SELECT contact_. as formula0_ FROM Contacts
  contact_ WHERE contact_.ContactId=@p0',N'@p0 int',@p0=14
  </code></pre>
  
  <p>What am I doing wrong? </p>