These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Can ICriteria.List() return proxy objects?
PostPosted: Sun Jul 16, 2006 10:46 pm 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
Is there any way to get a collection of proxy objects from ICriteria.List()? At the moment I'm doing it manually, but it seems like it would be a common thing to do.

Code:
IList<int> ids = session.CreateQuery("select p.ID from Person p").List<int>();
IList<Person> people = new List<Person>(ids.Count);

foreach (int id in ids)
{
    people.Add(session.Load<Person>(id));
}

foreach (Person person in people)
{
    Debug.Assert(!NHibernateUtil.IsInitialized(person));
    //loaded here
    Console.WriteLine(person.Name);
}


Also, is it possible to pick and choose which properties are proxied and which aren't (without multiple tables and one-one relationships)? A lot of my objects have a ValidFromDate property that will be read 90% of the time and I want to avoid loading the rest of the object just because that date was looked at. If I try removing the "virtual" modifier from the property I get an invalid proxy exception.

Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:08 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:41 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
OK, I've spoken too soon again.
Here is the Jira issue: http://jira.nhibernate.org/browse/NH-429.
Now I've just got to find a way to get people to vote for it! (and stop answering my own forum questions while I'm at it)...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.