I'm using PagedList.Mvc for pagination of results.
But when doing the following action with the querys:
public ActionResult Index(int? page, string searchString)
{
int pageSize = 10;
int pageNumber = (page ?? 1);
var query = db.Grupos.AsQueryable();
if (!string.IsNullOrWhiteSpace(searchString))
{
searchString = searchString.ToUpper();
query = query.Where(x => x.Nome.ToUpper().Contains(searchString));
}
query = query.OrderByDescending(x => x.Id);
query = query.Select(x => new Grupo
{
Id = x.Id,
Nome = x.Nome
});
if (Request.IsAjaxRequest())
{
return PartialView("Lista", query.ToPagedList(pageNumber,pageSize));
}
return View(query.ToPagedList(pageNumber,pageSize));
}
I encounter the following error when executing query.ToPagedList (pageNumber, pageSize):
Additional information: The entity or complex type 'Projeto.Entity.Grupo' cannot be constructed in a LINQ to Entities query.
I would like my query to search only the Id and Name of this group