http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx

<http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx>

On Tue, Sep 7, 2010 at 12:07 PM, Calin <[email protected]> wrote:

> Hi Nadav,
>
>  "you can actually just query for the products of all you're
> entities," This looks the most appealing, how do I actually do this ?
> You mean I shoud call a FetchAll for entities and FetchAll for
> products and then the lazy loader for entities will now how to load
> entity.Products based on the collection that I fetched previously ?
>
> "by the way, why don't you put your domain business logic inside your
> nhibernate mapped entities? "
>  Yes, why don't I ? It has something to do with my business layer, I
> find it very hard to map collections into my business object, I use
> CSLA, and there are some issues here specific to my application.
>
> On Sep 7, 5:22 pm, nadav s <[email protected]> wrote:
> > hi Calin. The main performance issue with your code isn't lake of use of
> > your multi core proccessor, but a classical N+1 problem.
> >
> > you're enumerating an enumeration of entities, lazy loading their
> > collection, now unless you have set a big batch size, if you have 100
> > entities, and you are have one one-to-many relationship, you're gonna
> have
> > here 101 queries (thus N+1) - one for the entities (the previous query)
> and
> > 1 query per a returned entity.
> >
> > you can actually just query for the products of all you're entities, and
> > then you'll have only 2 queries, one fetching the entities, and one
> fetching
> > the products.
> >
> > by the way, why don't you put your domain business logic inside your
> > nhibernate mapped entities?
> >
> > On Tue, Sep 7, 2010 at 4:28 PM, Graham Bunce <[email protected]
> >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > ... however if you did want to do this then you'd need some framework
> > > to manage the sessions for you.
> >
> > > the best way may be to wrap each Create within a method that manages
> > > the session for you e.g. (semi pseudo-code)
> >
> > > Parallel.ForEach(() => { ServiceLayer.Create(entity); };
> >
> > > ServiceLayer.Create<T>(T entity)
> > > {
> > >  try
> > >  {
> > >     NH.Session.Open();
> > >     //Do Stuff
> > >  }
> > >  finally
> > >  {
> > >     NH.Session.Close();
> > >  }
> > > }
> >
> > > Or something along these lines. Make sure that the entity you pass is
> > > either a DTO (safer IMO) or you attach it to the new session within
> > > the Create method. There may be some quirks with the latter though.
> > > I've done some multi-threaded stuff with NH but not a huge amount so
> > > there might be a problem with the above... but I've done something
> > > similar myself and, so far, no issues I've come across.
> >
> > > --
> > > 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]>
> <nhusers%[email protected]<nhusers%[email protected]>>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/nhusers?hl=en.
>
> --
> 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.
>
>

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