Try our conversational search powered by Generative AI!

FindPagesWithCriteria and strongly typed pages

Vote:
 

Hello,

I have a method looking like this:
IList<AnnouncementPage> GetAnnouncements(AnnouncementType announcementType);

In the end of the method I want to get some pages (of the type AnnouncementPage) from a container.

If I do like this its all good except that I might get some other pages in that container aswell that is NOT an AnnouncementPage:

var announcements = _contentRepository.GetChildren<AnnouncementPage>(announcementContainer);
return announcements.OrderByDescending(a => a.Changed).ToList<AnnouncementPage>();

So instead I tried using FindPagesWithCriteria: 

var announcements = queryService.FindPagesWithCriteria(announcementContainer, criterias);

The problem now is that this return a PageDataCollection which I dont want. I want a generic list as i got before. I have tried .ToList<AnnouncementPage>() but that didn't work. Of course i can loop through the PageDataCollection and one by one put them in a generic List. But then its unneccessary to even use FindpagesWithCriteria.

So my question is: Is there a way to use FindPagesWithCriteria and get a generic list instead so I can use my strongly typed pages and not PageData objects.

My ques

#72888
Jul 02, 2013 12:45
Vote:
 

You could use something like this maybe:


            var pdc = DataFactory.Instance.GetChildren<AnnouncementPage>(announcementContainer);
            FilterForVisitor.Filter(pdc);
            var somelist = pdc.OfType<AnnouncementPage>().ToList();
       

    

#72896
Edited, Jul 02, 2013 14:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions 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.