November Happy Hour will be moved to Thursday December 5th.

Get latest topics in specific forum

Vote:
 

Hi!

I have a problem which is causing me much frustration. hehe :-)

I want to search for the latest topics in a specific forum. In other words I don't want to search club forums. Just the standard forum. Anyways, I took a look in the db and found out that the ID for forum is 3 and then I wrote this.

TopicQuery topicQuery = new TopicQuery();
topicQuery.CreateDate = new DateTimeCriterion();
topicQuery.Room = new RoomCriterion();
topicQuery.Room.Forum = new ForumCriterion();
topicQuery.Room.Forum.ID = new IntegerCriterion();
topicQuery.Room.Forum.ID.Value = 3;
topicQuery.OrderBy.Add(new CriterionSortOrder(topicQuery.CreateDate, EPiServer.Common.Sorting.SortingDirection.Descending));
MessageCollection topics = QueryHandler.GetQueryResult<EPiServer.Community.Forum.Topic, MessageCollection>(topicQuery, 1, 5);

Gives me no hits even though there is plenty of topics in that forum?

Someone help?

Thanks

#42194
Aug 12, 2010 12:48
Vote:
 

Hi,

It sounds like the rooms containing the topics you're searching for are subrooms of another room, and this is why your query doesn't return any hits. If the rooms are subrooms, you have use Room.Parent (see query)

A forum can contain several root rooms, which again can contain several subrooms, which contain topics.

If this is the case, your query should look like this:

TopicQuery topicQuery = new TopicQuery();
topicQuery.CreateDate = new DateTimeCriterion();
topicQuery.Room = new RoomCriterion();
topicQuery.Room.Parent = new RoomCriterion();
topicQuery.Room.Parent.Forum = new ForumCriterion();
topicQuery.Room.Parent.Forum.ID = new IntegerCriterion();
topicQuery.Room.Parent.Forum.ID.Value = 3;
topicQuery.OrderBy.Add(new CriterionSortOrder(topicQuery.CreateDate, EPiServer.Common.Sorting.SortingDirection.Descending));
MessageCollection topics = QueryHandler.GetQueryResult<EPiServer.Community.Forum.Topic, MessageCollection>(topicQuery, 1, 5);

Hope this helps!   

Karoline

#42232
Aug 14, 2010 15:08
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.