You can either expose the real collection so you can call IsInitialized() on it, or you can add an IsApplicationRolesInitialized() method on your domain class. The first solution obviously breaks encapsulation, the second adds dependency of NHibernate to your domain class. A third option that prevents both is to use a delegate; but the syntax is kind of ugly:
Code:
public delegate bool IsInitializedDelegate(object enitityOrCollection);
public bool IsApplicationRolesInitialized(IsInitializedDelegate isInitialized)
{
return isInitialized(this.realApplicationRolesCollection)
}
and call it like this
Code:
User user = session.Load<User>(someId);
Assert.IsFalse(user.IsApplicationRulesInitialized(NHibernateUtil.IsInitialized));
There are many ways to skin a cat.
Ultimately, NHibernate only care that the collection is an IList or its generic variant. To throw an exception on an "unknown collection", it means going through the meta data and basically do a validation on every IsInitialized() call. Someone else is going to complain about performance problem then. Like everything, there is always a trade off. In this case, it has been chosen to leave that responsibility with the user/programmer. Hope this make sense.