Continue from previous post. I've re-factored the solution

The generated hbm for Parent:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="property" auto-import="true" default-cascade="none" default-
lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" mutable="true"
name="Parent" table="`Parent`">
    <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Id" />
      <generator class="identity" />
    </id>
    <set access="field.pascalcase-underscore" cascade="all"
inverse="true" lazy="true" name="Child" mutable="true">
      <key>
        <column name="Parent_id" />
      </key>
      <one-to-many class="Child" />
    </set>
  </class>
</hibernate-mapping>

And child:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="property" auto-import="true" default-cascade="none" default-
lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" mutable="true"
name="Child" table="`Child`">
    <id name="Id" type="System.Int32">
      <column name="Id" />
      <generator class="identity" />
    </id>
    <property name="Date" type="System.DateTime">
      <column name="Date" not-null="true" />
    </property>
    <many-to-one cascade="none" class="Parent" name="Parent">
      <column name="Parent_id" />
    </many-to-one>
  </class>
</hibernate-mapping>

As you can see, plain simple.

And the query:
var P1 = ses.Get<Parent>(1);
P1.Child.Count();

The generated SQL:
SELECT child0_.Parent_id as Parent3_1_,
       child0_.Id        as Id1_,
       child0_.Id        as Id4_0_,
       child0_.Date      as Date4_0_,
       child0_.Parent_id as Parent3_4_0_
FROM   [Child] child0_
WHERE  child0_.Parent_id = 1 /* @p0 */

Ken





On Apr 8, 8:21 am, Kenneth <[email protected]> wrote:
> Hi Fabio
>
> I'm using plain session.Get<Parent>(1), and the child collections is
> lazyloaded. And it's happening when I access the child collection.
>
> Parent map:
>     public class ParentMap : ClassMap<Parent>
>     {
>         public ParentMap()
>         {
>             Id(x => x.Id)
>                 .GeneratedBy.Identity()
>                 ;
>
>             HasMany<Child>(x => x.Child)
>                 .Access.PascalCaseField(Prefix.Underscore)
>                 .Inverse()
>                 .AsSet()
>                 .LazyLoad()
>                 .Cascade.All()
>                 ;
>
>         }
>     }
>
> Child map:
>
>     public class ChildMap : ClassMap<Child>
>     {
>         public ChildMap()
>         {
>             Id(x => x.Id)
>                 .GeneratedBy.Identity()
>                 ;
>
>             Map(x => x.Date)
>                 .Not.Nullable()
>                 ;
>
>             References<Parent>(Reveal.Property<Child>("Parent"))
>                 .Cascade.None()
>                 ;
>         }
>     }
>
> Ken
>
> On Apr 7, 9:38 pm, Fabio Maulo <[email protected]> wrote:
>
> > The mapping is generated and is a little bit difficult to read...
> > btw even the SQL is generated by NH and what is important is the original
> > query.
> > Which is the query ? (HQL, Criteria, QueryOver, Linq)
>
> > 2010/4/7 Kenneth <[email protected]>
>
> > > Taken from NHProf:
> > > SELECT cancellati0_.Subscription_id as Subscrip3_1_,
> > >       cancellati0_.Id              as Id1_,
> > >       cancellati0_.Id              as Id5_0_,
> > >       cancellati0_.Date            as Date5_0_,
> > >       cancellati0_.Subscription_id as Subscrip3_5_0_
> > > FROM   [CancellationDate] cancellati0_
> > > WHERE  cancellati0_.Subscription_id = 1 /* @p0 */
>
> > > Maps:
> > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
> > > access="property" auto-import="true" default-cascade="none" default-
> > > lazy="true">
> > >  <class xmlns="urn:nhibernate-mapping-2.2" mutable="true"
> > > name="SubscriptionWithData.CancellationDate, SubscriptionWithData,
> > > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
> > > table="`CancellationDate`">
> > >    <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0,
> > > Culture=neutral, PublicKeyToken=b77a5c561934e089">
> > >      <column name="Id" />
> > >      <generator class="identity" />
> > >    </id>
> > >    <property name="Date" type="System.DateTime, mscorlib,
> > > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
> > >      <column name="Date" not-null="true" />
> > >    </property>
> > >    <many-to-one cascade="none"
> > > class="SubscriptionWithData.Subscription, SubscriptionWithData,
> > > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
> > > name="Subscription">
> > >      <column name="Subscription_id" />
> > >    </many-to-one>
> > >  </class>
> > > </hibernate-mapping>
>
> > > Is there a reason why NH selects the same column multiple twice?
>
> > > Ken
>
> > > --
> > > 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]<nhusers%[email protected]>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/nhusers?hl=en.
>
> > --
> > Fabio Maulo

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