well there really isn't much more documentation than what is online, in the .chm file, the source code, and the Hibernate in Action book as far as I know. And they're all pretty close the the same terse notes on how to use it. Not alot about when and what situations.
Quote:
but what if I have many lazy collections, and I only want "Cities" to be loaded?
All session.Lock() really does is reassociate a detached object with a new session so basically you will only instantiate a lazy collection if you access it. this is the same behavior as if you are accessing the lazy collection in the same session that you originally loaded the object. more specifically:
Code:
Country c = (Country) session.Load(typeof(Country), 1);
foreach (State s in c.States)
Console.Write(s.Name);
session.Close();
is basically the same (with regard to lazy loading) as:
Code:
Country c = (Country) session.Load(typeof(Country), 1);
session.Close;
...
sessionTwo.lock(c, LockMode.None);
foreach (State s in c.States)
Console.Write(s.Name);
sessionTwo.Close();
in each instance, the c.States collection will be loaded because the Country object is attached to a session. No other lazily loaded collections would be loaded until they were accessed in a similar manner. this points to something I overlooked in answering your first question:
Quote:
If I have a collection inside a class (let's say "Country" has a collection of "States"), and the collection is marked as lazy-load... How do I reach that collection when I need it?
if you are accessing the collection in the same session that you originally loaded the object, NH will load the collection immediately. so unless you are closing the session before you are accessing the collection, your collection should be available the first time you use it.