Linqクエリの結果をMVC.Webgridに渡そうとすると、エラーが発生します(簡略化されています)。
The model item passed into the dictionary is of
type'System.Data.Entity.Infrastructure.DbQuery but
this dictionary requires a model item of type
'System.Collections.Generic.IEnumerable`1[MyModel.Models.MyMetric]'
これは失敗するActionResultです:
public ActionResult Test()
{
var metrics = db.Metrics
.GroupBy(c => c.Year)
.Select(g => new
{
Year = g.Key,
Q1 = g.Where(c => c.Quarter == 1).Sum(c => c.Value),
Q2 = g.Where(c => c.Quarter == 2).Sum(c => c.Value),
Q3 = g.Where(c => c.Quarter == 3).Sum(c => c.Value),
Q4 = g.Where(c => c.Quarter == 4).Sum(c => c.Value)
});
return View(metrics);
}
元のデータのピボットを作成しているので、ある種の新しいモデルを作成する必要があると思いますが、このコンテキストでそれを行う方法がわかりません。(EFとMVCで足を濡らすだけです)
何か案は?
TIA J