Hello,
I'd like to get some help with a HQL syntax. Here are my classes :
class Post
{
Source theSource ;
}
class Source
{
IList<Post> Posts;
}
In the mapping of Source I have :
<bag name="Posts" lazy="true">
<key column="SourceID" />
<one-to-many class="Post"/>
</bag>
and in the mapping of Post I have :
<many-to-one class="Source" name="theSource" cascade="all-delete-
orphan" column="SourceID" />
Now what I want is to get a list of all the source entities that are
used by all the post entities created in a given date range :
ICriteria sourceCriteria = SessionManager.GetCurrentSession
().CreateCriteria(typeof (Source));
sourceCriteria.CreateCriteria("Posts")
.Add(Restrictions.Lt("DateCreated", DateTime.Parse(parameter.Attribute
("enddate").Value)))
.Add(Restrictions.Gt("DateCreated", DateTime.Parse(parameter.Attribute
("startdate").Value)));
//make sure we get distinct Source
sourceCriteria.SetResultTransformer(new
DistinctRootEntityResultTransformer());
return sourceCriteria.SetMaxResults(100).List<Source>();
That works fine. Now let's change the Source class slightly :
class Source
{
IList<Post> Posts;
int countPosts;
}
I still don't want to load the Posts list (you've noticed that I used
lazy-loading), however I would like my query to fill in the countPosts
property with the number of Posts using each publication.
How do I do that using the above HQL ?
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---