Вопрос

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.

Это было полезно?

Решение

Use NHibernateUtil:

var isInitialized = NHibernateUtil.IsInitialized(entity.Collection);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top