Try our conversational search powered by Generative AI!

Dynamic Data Store

Vote:
 

If I use the Dynamic Data Store to store, lets say, page ratings; is there any way I can retrieve a list of all pages that have been rated (for example, if I wanted to show a "highest rated pages" function? In other words, what I'm looking for is something along the lines of PageDataCollection pdc = EPiServer.Data.Dynamic.InsertMagicClassHere.GetPagesThatReference<MyRatingClass>();

Brgds/Niklas

#37962
Mar 24, 2010 19:57
Vote:
 

I havent used page objects if thats what you are doing? But if you are using a regular object stored in DDS you could just fire a LINQ query to get the top 10 ratings (Take(10), orderby).

#37976
Mar 25, 2010 9:16
Vote:
 

Hi Niklas!

I depends a little on how you store the ratings. If you use the "PageObjects"-mechanism, then there is currently no easy way to query for pageobjects for a set of pages.

But, if you manage the "connection to the page" yourself, for example by using a PageID property in your Rate-class, then you could use some clever LINQ-queries to retrieve for example the top 5 rated pages.

Consider for example a Rate-class like this:

public class PageRate
{
   public int PageID { get; set }
   public int Rate { get; set; }
   public DateTime Rated { get; set; }
   public string RatedBy { get; set; }
}

(Each rating would be stored as a single instance of the above class).

Now, using a groupby-LINQ-query, the top 5 rated pages could be retrieved in "one stroke" like so:

var query = from pageRate in pageRateStore.Items<PageRate>()
            group pageRate by pageRate.PageID into g
            orderby g.Average(i=>i.Rate) descending
            select new { PageID = g.Key, AvgRate = g.Average(i=>i.Rate) };

foreach( var pageRate in query )
{
 Response.Write(String.Format("{0}:{1}<br>", pageRate.PageID, pageRate.AvgRate));
}

Unfortunately there is a bug that wont let you add a ".Take(5)" to the groupby-query to just retrieve the top 5
pages, i.e. something like this:

foreach( var pageRate in query.Take(5) )

I'll have a look into this bug, I guess it's quite easy to fix and hopefully will make it into the first servicepack.

Regards,
Johan Olofsson

#37978
Mar 25, 2010 10:04
Vote:
 

Thanks alot for an excellent explanation/example! And yes, I was using the PageObject-mechanism.

#37993
Mar 25, 2010 22:42
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.