TotalViews でクエリを並べ替えることができるようにするには、コンテンツ ビュー カウンター モジュール内のいくつかのコード部分を変更する必要があります。
1)モデルの修正
public class UserViewRecord : ContentPartRecord
{
public virtual int TotalViews { get; set; }
}
public class UserViewPart : ContentPart<UserViewRecord>
{
[Required]
public int TotalViews
{
get { return Record.TotalViews; }
set { Record.TotalViews = value; }
}
}
実際には、合計ビューを保存できるときにテーブルを作成します。したがって、さらに2つの手順に従う必要があります
2) migration.cs にコードを追加します。
public int UpdateFrom2() {
SchemaBuilder.CreateTable("UserViewRecord", table => table
.ContentPartRecord()
.Column("TotalViews", DbType.Int32)
);
ContentDefinitionManager.AlterPartDefinition(
typeof(UserViewPart).Name, cfg => cfg.Attachable());
return 3;
}
3) ハンドラー クラスを変更して、UserViewRecord の IRepository をこの部分のストレージとして使用する必要があることを指定します。
public UserViewPartHandler(IVotingService votingService,
IOrchardServices orchardServices, IRepository<UserViewRecord> repository)
{
_votingService = votingService;
_orchardServices = orchardServices;
Filters.Add(StorageFilter.For(repository));
//more code
//more code
}
結局、Bertrand Le Roy が言ったように、TotalViews プロパティのバインドを追加して、TotalViews を並べ替え基準として使用できます。