Is the problem too many queries, or that you absolutely cannot have
more than one roundtrip to the database?
[...]
>
> var r = s.QueryOver<NHMapTest1>()
> .Where(x => x.Id == id)
> .Future();
>
> s.QueryOver<NHMapTest2>()
> .Where(x => x.Parent.Id == id)
> .Future();
> Running r.Single(); returns the entity, but if you do .Items it'll
> query the DB, even tho they were selected in the 2nd future. Both
> queries run correctly and return valid results.
When you access the collection, even though a number of objects of the
collection's member type has been loaded, NH doesn't know they are
part of the collection, that's why it needs to query again. Looking at
the child's Parent reference of loaded objects wouldn't be enough,
since it doesn't know if those are _all_ the children.
Have you set proper batch size on your collections and classes? And
possibly specify subselect fetching for the collections. With that you
should be able to rely on lazy fetch, but with a limited number of
round trips.
/Oskar
Interesting! I was wondering the same myself recently, and this seems to
be exactly what I need. Is there any information available how this can
be done with the LINQ-provider? I guess, it's "just" a matter of putting
the right nodes into the expression tree. I was looking at the reference
on NHforge, but didn't see anything pertinent.
Best Regards, David
Another point to consider is that this sounds like some sort of report
page, which isn't exactly what NHibernate is optimized for. If this is
true, it may be useful to just use SQL to project the data to a
dataset or some simple view model and forget about the entities for
this case. There might also be the option of caching the "compiled"
view model in memory or serialized in e.g. a nosql database.
How many objects are we talking about in each level here? If the
numbers grow beyond perhaps 10000 or so I would expect you to
experience sluggishness from NHibernate having to create all those
objects, even if data is fetched efficiently from the database.
/Oskar
2012/2/2 Brad Laney <brad.j...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To post to this group, send email to nhu...@googlegroups.com.
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
>
Obviously you know your system much better than me, but here are some
additional thoughts:
On batch size:
It's late evening for me so forgive me if I have a mental accident
here, but it seems to me that with proper batch size on the
collections you should be able to get something similar to the
following scenario:
Listing { Set<Item> Items }
Item { Set<Property> Properties }
Property { Name, Value }
Query 1: session.Query<Listing>().BlaBla.ToList().
Query 2: access loadedListings[0].Items.First(), will load the Items
collection for ALL loaded listings
Query 3: access loadedListings[0].Items.First().Properties.First(),
will load the Properties collection for ALL loaded Items
Done.
Tree structures:
Have you considered other methods of efficiently loading tree
structures from SQL, such as "nested set" and "materialized path"? On
the other hand, since you have a known and limited depth, those
methods may not get you much compared to regular joins.
On report:
To me, the concept of reading and displaying a large amount of data to
the user is a kind of report, in that it reports the contents for the
system. This is a factor behind the concept of
command/query-separation and using separate view models (where the
data may be stored denormalized to increase read performance). Btw, it
sounds like you are putting a lot of data in front of the user in a
single view. Is the user really able to cope with all that data at
once?
Domain logic:
When you display all this information to the user, do you really need
(significant parts of) the domain logic in your domain model? If not,
then it may be that NHibernate isn't the right tool for this use case.
If you don't have a rich domain model, perhaps NHibernate isn't the
correct tool for this project. If you do have a rich domain model,
there may still be areas of the application which isn't optimal.
Everything is a compromise. (In some projects of mine I have many use
cases where I need to load less than 10 objects, usually less than
three levels deep.)
If you don't really need anything in the entities for this usecase,
perhaps loading the data using raw SQL and NOT building the entities
is useful.
On the other hand, if someone came up with a nice solution to
efficiently load such structures, it seems like an interesting new
feature for NHibernate. :)
/Oskar
2012/2/6 Brad Laney <brad.j...@gmail.com>: