1
When trying to make a list where you will filter only the 5 largest records by values in descending order I am experiencing this error:
CS0266 error Cannot convert type implicitly "System.Linq.Iqueryable" in "System.Collections.Generic.Icollection". There is an explicit conversion (there is an absent 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);
}
}