Sort for TotalViews

Topics: Customizing Orchard
Dec 23, 2011 at 5:19 PM

Hi,

I try to sort my list following order

UserViewPart part;           

            var containers = _contentManager.Query<ArticlesPart, ArticlesPartRecord>(VersionOptions.Latest).List();

            var descendingOrder = part.TotalViews == (int)OrderByDirection.Descending;
            containers = containers.OrderBy<ArticlesPart, ArticlesPartRecord>(part.TotalViews, descendingOrder);

But this raise compile error

Error 2 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<eProp.Articles.Models.ArticlesPart>' to 'System.Linq.IQueryable<eProp.Articles.Models.ArticlesPart>' E:\Arruni\Arruni\Sean Baumann\Orchard\src\Orchard.Web\Modules\eProp.Articles\Services\ArticleService.cs 61 26 eProp.Articles

 

How can i correct this?

 

lakmal

Coordinator
Dec 23, 2011 at 8:30 PM

You're probably missing a using System.Linq statement, but one also has to wonder why you don't do the orderby before you call List?

Dec 25, 2011 at 7:21 AM

I have use this code

return _contentManager.Query<UserViewPart>().List().OrderBy(bc=>bc.As<UserViewPart>().TotalViews );   

 

List is comming, but its not sort order for totalview

 

Dec 25, 2011 at 4:43 PM

Hi,

I have created my own widget for that

https://gallery.orchardproject.net/List/Modules/Orchard.Module.galgodage.TopViews

Here is video how u can use it

http://youtu.be/fyev43yv9TM 

 

lakmal