views:

365

answers:

1

I am trying to load a sortable jqgrid 3.5 from a query with multiple joins in it and having much difficulty as I am a novice with both Linq and jqgrid. In order to allow for sorting I first was attempting to load it using dynamic sql. Since I am pulling columns from multiple tables I assume my return will be a class object which I will populate (or will it be a table). How can I return a Iqueryable custom class object when using dynamic sql with multiple .JOIN clauses. If this is impossible how do I return Iqueryable data from a stored procedure call. It is easy to create dynamic sql in the stored proc - I am unsure how to load my grid with it however. Sorry if this is all over the place but I can't seem to find a way. If you can recommend the most straight forward way to load my sortable grid from a query which has multiple joins in I am much appreciated.

my controller code: public ActionResult GridData(string sidx, string sord, int page, int rows) { EquipTrak eqt = new EquipTrak();

        var equipment = eqt.GetGridEquipment(sidx, sord);


        var dataJson = new
        {

            total = 10000,
            page = 1,
            records = 10000,
            rows = (from e in equipment
                    select new
                    {
                        equip_id = e.equip_id,
                        cell = new string[] {
                e.equip_id,
                e.equipType,
                e.makeType,
                String.Format("{0:MM/dd/yyyy}", e.serv_due_dt)
            }
                    }).ToArray()
        };
        return Json(dataJson);
    }
}

my class code (incomplete):

namespace ULS_Site.Models { public class EquipTrak {

    uls_dbDataContext ulsDB = new uls_dbDataContext();

    public IQueryable<equipmentCls> GetGridEquipment(string sidx, string sord)
    {

        try
        {

            return
A: 

Not sure if this is the best or worst solution but I used SQL Server views to handle all the joining required. I could then use .Orderby and .Where against the view which was in my data context.

MikeD