After a little more digging I found the IQuery.Enumerable<T>() method which does return proxies. This cuts my example down to:
Code:
IEnumerable<Person> people = session.CreateQuery("from Person").Enumerable<Person>();
foreach (Person person in people)
{
Debug.Assert(!NHibernateUtil.IsInitialized(person));
Console.WriteLine(person.Name); //loaded here
Debug.Assert(NHibernateUtil.IsInitialized(person));
}
It means that I have to use HQL instead of ICriteria and I have to manually wrap the IEnumerable<T> in an IList<T>, but this shouldn't cause any issues.
Anyway, onto my second question about non-proxied fields in a proxied class. It turns out that the "lazy" attribute is a supported property attribute in Hibernate but hasn't been ported to NHibernate (
http://forum.hibernate.org/viewtopic.php?t=962152).
Are there any plans to port this across in the near future?
Should I be creating a Jira feature request?
I noticed that contributions are welcomed. Is this trivial enough for an experienced programmer who's only moderately experienced in NH?
Cheers.