For using MVC JqGrid following this tutorial I'm adding some Linq extensions, basically these:
public static IQueryable<T> OrderBy<T>(this IQueryable<T> query, string sortColumn, string direction)
{
//...
return query.Provider.CreateQuery<T>(result);
}
public static IQueryable<T> Where<T>(this IQueryable<T> query,
string column, object value, WhereOperation operation)
{
//....
return query.Provider.CreateQuery<T>(result);
}
Thing is that I don't really like the idea of having these extension methods accessible for any query as I consider them to be very related to the JqGrid so I was trying to create a IJqQueryable that extends the IQueryable and then these two would be something like:
public static IJqQueryable<T> OrderBy<T>(this IJqQueryable<T> query, string sortColumn, string direction)
{
//Same code as before
var normalQuery = query.Provider.CreateQuery<T>(result);
return normalQuery as IJqQueryable<T>;
}
public static IJqQueryable<T> Where<T>(this IJqQueryable<T> query,
string column, object value, WhereOperation operation)
{
//Same code as before
var normalQuery = query.Provider.CreateQuery<T>(result);
return normalQuery as IJqQueryable<T>;
}
For that I only created this interface:
public interface IJqQueryable<T> : IQueryable<T>
{
}
And now my problem is that I would need the equivalent to AsQueryable() because my controller action method looks like (before the change to use IJqQueryable)
public JsonResult ComplaintTypes(GridSettings grid)
{
var complaintTypes = _queryComplaintTypes.GetAll();
Func<ComplaintType, Object> lambda = (complaintType => (new {
complaintType.ComplaintDescription,
complaintType.ComplaintTypeId
}));
var result = _jqGridFactory.Get(grid, complaintTypes.AsQueryable(), lambda);
return Json(result, JsonRequestBehavior.AllowGet);
}
and apparently I can't use as IJqQueryable or cast it to (IJqQueryable) complaintTypes.
Hope I made it reasonably clear, will appreciate any idea
Thanks