views:

54

answers:

1

I'm trying to query the set of forums (fora?) for the user's clubs to get the latest topics and replies in those forums. This is the code I'm using:

RoomCollectionCriterion userClubRoomsCollection = new RoomCollectionCriterion();

foreach (Club userClub in userClubCollection)
{
    RoomCriterion userClubRoomCriterion = new RoomCriterion();
    userClubRoomCriterion.ID = new IntegerCriterion();
    userClubRoomCriterion.ID.Value = userClub.ForumRoom.ID;

    userClubRoomsCollection.Criteria.Add(userClub.Name, userClubRoomCriterion);
}

TopicQuery topicQuery = new TopicQuery();

topicQuery.Room = new RoomCriterion();
// Pass in our collection of the user's clubs to the query
topicQuery.Room.Rooms = userClubRoomsCollection;

MessageCollection topics = QueryHandler.GetQueryResult<EPiServer.Community.Forum.Topic, MessageCollection>(topicQuery, pageNumber, 2);
MessageCollection replies = QueryHandler.GetQueryResult<EPiServer.Community.Forum.Topic, MessageCollection>(topicQuery, pageNumber, 4);

The problem I have is that every time I hit the first call to GetQueryResult, I get a NullReferenceException. I can't see anything wrong/missing with what I'm passing in to GetQueryResult, but I'm hoping somebody else has done this previously and can suggest a fix for this.

Update 26/10/2010
As suggested by Magnus I swapped out my QueryHandler.GetQueryResult for a call to ForumHandler.GetQueryResult but this doesn't seem to have made a difference. I've also trimmed down the parameters to GetQueryResult so that my line of code is now:

MessageCollection topics = ForumHandler.GetQueryResult(topicQuery);

but this still gives me a NullReferenceException. Which suggests to me the problem isn't in the GetQueryResult method of whichever handler I'm calling, it's in the topicQuery object, as that's the thing that's stayed constant so far. I'm wondering if I'm missing a property that needs to be set on the TopicQuery object.

Update 4/11/2010
Is there a "security context" that needs consideration here? i.e. the query needs to be run in the context of a user that has complete access to all forums?

+1  A: 

Try using EPiServer.Community.Forum.ForumHandler.GetQueryResult() and its overloads.

Magnus von Wachenfeldt
No joy. I swapped out my line for `MessageCollection topics = EPiServer.Community.Forum.ForumHandler.GetQueryResult(topicQuery, pageNumber, 2);` but I get the same NullReferenceException :-(
PhilPursglove