DataSourceResult Help

2 posts, 0 answers
  1. Allan
    Allan avatar
    34 posts
    Member since:
    Aug 2015

    Posted 24 Feb Link to this post


    I was wondering if there was any way to add conditions to a datasourcereulst like "Where" and"Union"?  Here is my controller code.

    public ActionResult tbl_vessels_Read([DataSourceRequest]DataSourceRequest request, decimal[] param_bhp, decimal[] param_deck)
              IEnumerable<tbl_vessels> tbl_vessels = db.tbl_vessels;
              DataSourceResult result = tbl_vessels.ToDataSourceResult(request,
                  c => new tbl_vessels
                  vessel_idx = c.vessel_idx,
                  vessel_name = c.vessel_name,               
                  spotlist_dp = c.spotlist_dp,
                  spotlist_bhp = c.spotlist_bhp,
                  spotlist_deck = c.spotlist_deck,
                  spotlist_bp = c.spotlist_bp,
                  spotlist_oilrec = c.spotlist_oilrec,
                  spotlist_fifi = c.spotlist_fifi,
                  spotlist_rov = c.spotlist_rov,
                  charterer_info = c.charterer_info
              JsonResult data;
              if (param_bhp == null && param_deck == null)
                  data = Json(tbl_vessels);
                  data = Json(tbl_vessels.Where(
                      w => w.spotlist_bhp > param_bhp[0] &&
                           w.spotlist_bhp < param_bhp[1] &&
                           w.spotlist_deck > param_deck[0] &&
                           w.spotlist_deck < param_deck[1]
              return data;

    As you can see I also have sliders which means that my dataresults need to be enumerable, IQueryable isn't allowed on array.  So how can I add some conditions to the DataSourseResult like "Where" etc??



  2. Rosen
    Rosen avatar
    3215 posts

    Posted 29 Feb Link to this post

    Hello Allan,

    The purpose of ToDataSourceResult is to apply the operations described in the DataSource descriptors. The equivalent of Where in this context is the Filter operation, therefore if you want to apply restrictions which to be processed by the ToDataSourceResult you should described them as a filter descriptors and merge them with those from the DataSourceRequest if such exist.  

    If you want to filter the collection externally, you should apply the Where clause before passing the data to the ToDataSourceResult. This will ensure that the results returned by the ToDataSourceResult are correct, for example that the correct number of records is returned to the client.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET AJAX banner
Back to Top