Question

I have a validation engine that iterates through all the properties of an object and checks if they are valid.

If I get an Entity and change a simple property and run it through the engine it hydrates all of the lazyloaded collections.

In other words it gets the collection and iterates through the entities in that collection. If the collection has already been retrieved than that is fine but if it has not been retrieved then there is no reason it would be invalid so there is no reason to go get it.

In short, can I inspect a collection and see if it has been retrieved yet. If I can do that then I can skip or iterate that collection accordingly.

Was it helpful?

Solution

Use NHibernateUtil:

var isInitialized = NHibernateUtil.IsInitialized(entity.Collection);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top