I am following Phil Haacks tutorial on using JQGrid with ASP.Net MVC. My application is ASP.Net MVC 3 using Entity Framework 4.
I have the following code to perform the sorting and paging for my data which is returned to the JQGrid
var query = equipService.GetAllEquipment().AsQueryable()
.OrderBy("it." + sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);
However, this code creates an error at the .OrderBy("it." + sidx + " " + sord) line. The error is
System.Linq.Queryable.OrderBy<TSource,TKey>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,TKey>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
The query is calling a method, GetAllEquipment(), in my service layer which looks like this
public List<Equipment> GetAllEquipment()
{
List<Equipment> equipList = new List<Equipment>();
equipList = equipRepository.GetAllEquipment();
return equipList;
}
This method, then calls the same name of method in my repository, like so
public List<Equipment> GetAllEquipment()
{
var query = (from e in Data.DBEntities.Equipments
select e).ToList();
return query;
}
I can kind of solve the problem by creating an instance of my objectcontext in my controller method and use this code
using (AssetEntities context = new AssetEntities())
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = context.Equipments.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var query = context.Equipments
.OrderBy("it." + sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);
}
However, I don't really want to do this, rather I would like to keep to the repository pattern I use throughout my application for all database interaction.
Any ideas on how I can fix this?
Thanks as ever everyone.