My collection was in fact NOT initialized!  I was passing the wrong 
property name to ICriteria.SetFetchMode, which should probably be 
refactored to take a lambda expression instead of a string as to avoid such 
problems.  Well, I still think the NH code I posted is confusing but at 
least it works.


On Saturday, December 8, 2012 8:33:47 PM UTC-5, HappyNomad wrote:
>
> In AbstractPersistentCollection, there is this method:
>
>         /// <summary> Called by the <tt>Count</tt> property</summary>
>         protected virtual bool ReadSize()
>         {
>             if (!initialized)
>             {
>                 if (cachedSize != -1 && !HasQueuedOperations)
>                 {
>                     return true;
>                 }
>                 else
>                 {
>                     ThrowLazyInitializationExceptionIfNotConnected();
>                     CollectionEntry entry = 
> session.PersistenceContext.GetCollectionEntry(this);
>                     ICollectionPersister persister = entry.LoadedPersister;
>                     if (persister.IsExtraLazy)
>                     {
>                         if (HasQueuedOperations)
>                         {
>                             session.Flush();
>                         }
>                         cachedSize = persister.GetSize(entry.LoadedKey, 
> session);
>                         return true;
>                     }
>                 }
>             }
>             Read();
>             return false;
>         }
>
> Notice that the call to Read() if the collection is already initialized.  
> Read() calls Initialize() which calls InitializeCollection().  Is it just 
> me, or does this indeed make no sense?  Why would you initialize a 
> collection that is already initialized?  I am asking because this unneeded 
> activity by NH is causing an issue in my app.  The scenario arises when I 
> try to find out the Count of a collection that was just been read from the 
> database.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/sBzSiIr0h7IJ.
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