try to recreate the issue without the code and the mapping inside your
"...".

2009/9/9 Francisco Lozano <[email protected]>

>
> The manual confirms my case:
>
> 17.5.3. Bags and lists are the most efficient inverse collections
>
> Just before you ditch bags forever, there is a particular case in
> which bags (and also lists) are much more performant than sets. For a
> collection with inverse="true" (the standard bidirectional one-to-many
> relationship idiom, for example) we can add elements to a bag or list
> without needing to initialize (fetch) the bag elements! This is
> because IList.Add() must always succeed for a bag or IList (unlike an
> ISet). This can make the following common code much faster.
>
>
>
> Any hint?
>
> On Sep 9, 1:44 pm, "Francisco A. Lozano" <[email protected]> wrote:
> > Hi,
> >
> > I have an entity named Users, which has a one-to-many relation with
> > another entity called Relationship. It is mapped as a bi-di bag.
> >
> > With my just-purchased NHProf license (thankyou Ayende!) I'm checking
> > my most-common use-cases against future performance problems.
> >
> > I have a CreateContact method in User, which creates an instance of
> > Relationship and adds it to its Relationships collection.
> >
> > With NHProf I've just noticed that NHibernate is initializing the
> > "Relationships" bag on Users when I do ".Add" on that property!
> > Why does it do it? I thought that <bag /> semantics didn't require to
> > initialize ... or at least in Java-Hibernate I remember moving from
> > <set ..> to <bag ...> in many places because of this very issue...
> >
> > My classes and mapping:
> >
> >     public class User : Entity
> >     {
> > ....
> >          public virtual ICollection<Relationship> Relationships { get;
> set; }
> > ....
> >         public virtual Relationship CreateContact(User user, string
> message)
> >         {
> >             if (Relationships == null)
> >                 Relationships = new List<Relationship>();
> >
> >             Relationship r = new Relationship()
> >             {
> >                 Message = message,
> >                 Contact = user,
> >                 Owner = this
> >             };
> >             Relationships.Add(r);
> >             return r;
> >         }
> > ....
> >     }
> >
> >     public class Relationship : Entity
> >     {
> > ....
> >         public virtual User Owner { get; set; }
> > ....
> >
> >     <class name="W.Domain.Users.User, W.Domain">
> >
> >         <id name="Id">
> >             <generator class="hilo" />
> >         </id>
> >
> >         <timestamp name="ModifiedAt" />
> >         <property name="CreatedAt" not-null="true" />
> >        .....
> >         <bag name="Relationships" inverse="true" lazy="true"
> > cascade="all-delete-orphan">
> >             <key column="owner" />
> >             <one-to-many class="W.Domain.Users.Relationship, W.Domain"/>
> >         </bag>
> >         ....
> >
> >     </class>
> >     <class name="W.Domain.Users.Relationship, W.Domain" >
> >         <id name="Id">
> >             <generator class="hilo" />
> >         </id>
> >         <timestamp name="ModifiedAt" />
> >         <property name="CreatedAt" not-null="true" />
> >         <property name="Message" length="250" not-null="false" />
> >         <many-to-one name="Owner" class="W.Domain.Users.User,
> > W.Domain" not-null="true" unique-key="AK_OWNER_CONTACT" />
> >         <many-to-one name="Contact" class="W.Domain.Users.User,
> > W.Domain" not-null="true" unique-key="AK_OWNER_CONTACT"/>
> >         <many-to-one name="Reciprocal"
> > class="W.Domain.Users.Relationship, W.Domain" not-null="false" />
> >     </class>
> >
> > This is the "offending" SQL:
> >
> > SELECT relationsh0_."owner" as owner5_1_, relationsh0_."id" as id1_1_,
> > relationsh0_."id" as id1_4_0_, relationsh0_."modified_at" as
> > modified2_4_0_, relationsh0_."created_at" as created3_4_0_,
> > relationsh0_."message" as message4_4_0_, relationsh0_."owner" as
> > owner5_4_0_, relationsh0_."contact" as contact6_4_0_,
> > relationsh0_."reciprocal" as reciprocal7_4_0_ FROM "relationship"
> > relationsh0_ WHERE relationsh0_."owner"=...@p0
> >
> > Francisco A. Lozano
> >
>


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