When trying to make a listing where I only filter the 5 largest records by values in descending order this error is occurring:
Error CS0266 Can not implicitly convert type "System.Linq.IQueryable" in "System.Collections.Generic.ICollection". Is there an explicit conversion (is there a missing conversion?)
Here is my code:
public class DashboardController : Controller
{
private NFeWebContext db = new NFeWebContext();
// GET: Dashboard
public ActionResult Index()
{
var dashboard = new DashboardViewModel();
var participantes = db.Participantes
.ToList();
var notas = db.NotasFiscais
.ToList();
var lista = db.NotasFiscais
.Where(x => db.Participantes.Any(y => y.ParticipanteId == x.ClienteID))
.GroupBy(z => z.ClienteID)
.Select(x => new NotaFiscal()
{
ClienteID = x.First().ClienteID,
ValorTotalNota = x.Sum(n => n.ValorTotalNota)
})
.OrderByDescending(x => x.ValorTotalNota)
.Take(5);
dashboard.NotasFiscais = lista;
return View(dashboard);
}
}