HappyNomad
unread,Dec 8, 2012, 8:33:47 PM12/8/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhu...@googlegroups.com
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.