I'm using 2.1CR1. I modified the nhibernate sample from here
http://weblogs.asp.net/pwilson/archive/2005/05/26/409042.aspx to work
with the new version

The class

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;
        }
        }
}

Here's the relevant mapping fragment

<class name="Wilson.NHibernate.Example.Contact,
WilsonNHibernateExample" table="Contacts" discriminator-value="?" >
                <id name="Id" column="ContactId" access="nosetter.camelcase" 
unsaved-
value="0">
                        <generator class="identity" />
                </id>
                <discriminator column="ContactType" />
                <property name="Name" column="ContactName" />
                <component name="Address" 
class="Wilson.NHibernate.Example.Address,
WilsonNHibernateExample" access="nosetter.camelcase">
                        <property name="Line" column="AddressLine" 
not-null="false" />
                        <property name="City" column="AddressCity" 
not-null="false" />
                        <property name="State" column="AddressState" 
not-null="false" />
                        <property name="Zip" column="AddressZip" 
not-null="false" />
                </component>

    <property name="PropertyWithFormula"  formula="('TestFormula')"
generated="always" />

                <bag name="Categories" table="CategoryContacts" cascade="none"
access="nosetter.camelcase" lazy="false" inverse="false">
                        <key column="ContactId" />
                        <many-to-many column="CategoryId"
class="Wilson.NHibernate.Example.Category, WilsonNHibernateExample" />
                </bag>
                <bag name="Details" cascade="all" access="nosetter.camelcase"
lazy="false" inverse="true">
                        <key column="ContactId" />
                        <one-to-many class="Wilson.NHibernate.Example.Detail,
WilsonNHibernateExample" />
                </bag>
                <subclass name="Wilson.NHibernate.Example.Person,
WilsonNHibernateExample" discriminator-value="P" />
                <subclass name="Wilson.NHibernate.Example.Business,
WilsonNHibernateExample" discriminator-value="B">
                        <property name="Company" column="CompanyName" />
                </subclass>
        </class>


======================================================

Here are the traces from SQL Server:
When I call session.Get<Contact>(1), the sql is correctly generated:
(''TestFormula'') as formula0_0_

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_.contact...@p0',N'@p0 int',@p0=1



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_
exec sp_executesql N'SELECT contact_. as formula0_ FROM Contacts
contact_ WHERE contact_.contact...@p0',N'@p0 int',@p0=14

What am I doing wrong?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to