Hibernate version: 1.2.0 GA
I have a lazy-loaded collection, which is fairly expensive to load. I'd like to cache the number of elements in that collection elsewhere. The logical place to update the cache seemed to be whenever the parent object is saved, so I added code like this:
if (NHibernateUtil.IsInitialized(parent.Collection))
{
cachedCount = parent.Collection.Count;
}
I wanted to avoid loading the collection when it wasn't necessary and figured that if it wasn't initialised then it couldn't have been modified, so there's no point updating the count. After some debugging, it turns out I was wrong: NHibernate adds a "queued write" and marks the collection as "dirty" while it's still not "initialised".
Is there any way that I can check whether the collection has been modified since it was loaded, but without loading it if it hasn't been loaded already?
|