This is a migrated thread and some comments may be shown as answers.

Kendo Dynamic Linq

1 Answer 632 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 20 Feb 2017, 06:48 PM

I see that Kendo has a Dynamic Linq library that handles the paging, sorting and filtering for you for MVC apps. I was reading about it here.  The following example is given:

<p>using Kendo.DynamicLinq;
 
public class EmployeesController : Controller {
 
  [HttpPost]
  public ActionResult Get(int take, int skip, IEnumerable<Kendo.DynamicLinq.Sort> sort, Kendo.DynamicLinq.Filter filter) {
    var employees = _context.Employees.OrderBy(e => e.Employee_ID)
      .OrderBy(e => e.Employee_ID)
      .Select(e => new Models.Employee {
        EmployeeID = e.Employee_ID,
        FirstName = e.First_Name,
        LastName = e.Last_Name,
        Title = e.Title,
        BirthDate = e.Birth_Date
    });
 
    return Json(employees.ToDataSourceResult(take, skip, sort, filter));
  }
}<br></p><p></p><p></p>

 

It seems to me that a problem with this approach is that there is no chance to do any mapping from the data entities which are returned from the database call to to a DTO entity. What I do in my app is execute a databaes call using EF and map the EF entity to an application entity. Is there a way I can still do this given the example above. In other words, I'd like the ToDataSourceResult function to create a Json document based on the mapped DTO entity and not the EF database entity.

1 Answer, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 22 Feb 2017, 09:47 AM
Hi Randy,

The Kendo DynamicLinq used in the controller is not part of Kendo UI. It is community supported as outlined at:

https://github.com/kendo-labs/dlinq-helpers#kendodynamiclinq

However, since you have also downloaded a trial for the UI for ASP.NET MVC wrappers, you may take advantage of the way that the data is filtered and parsed server-side with the Kendo..Extensions namespace, which is part of the Kendo.Mvc.dll).

Additionally, you can continue developing the rest of the application via JavaScript, there is no requirement to switch to  or  client-side.

The Kendo..Extensions namespace provides the DataSourceRequest object. The DataSourceRequest object needs to be decorated with the [DataSourceRequest] attribute to transport the Kendo UI Grid request information to the server in the correct format. Using this approach the data is returned to the Kendo UI Grid as correctly parsed JSON (grouped, filtered and sorted). 

The ToDataSourceResult()  method accepts an argument which allows you to map the data before sending it to the client, e.g:
people.ToDataSourceResult(dsRequest, map => new { Fullname = string.Format("Full name is {0} {1}", map.FirstName, map.LastName})

More information on the binding is available in the article below:
http://docs.telerik.com/aspnet-mvc/helpers/grid/binding/ajax-binding

Kind Regards,
Alex Hajigeorgieva
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or