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

Server binding kendo grid without exposing database context in the controller

3 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leah
Top achievements
Rank 1
Leah asked on 30 Apr 2018, 02:56 PM

Hi,

I am expecting a large amount of data to be displayed in the grid and used paging. I tried to use the Kendo.Mvc.Extensions ToDataSourceResult method but don't want to expose my context in the controller. Is there any way to achieve this?

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 02 May 2018, 11:35 AM
Hello Leah,

I would recommend you to use a Service Layer. In other words create a separate classes called "services". Put them in different class library (or namespace) project and make them independent on MVC framework infrastructure. 

You will find a sample which demonstrates the usage of a Service Layer in the link below:



Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Leah
Top achievements
Rank 1
answered on 03 May 2018, 09:09 AM

Hi Georgi,

I found a simple solution in stackoverflow by doing the code below.

The repository method with no reference to Kendo:

public T GetSales<T>(Func<IQueryable<SalesOrderHeader>, T> processQueryable)
{
    using (var c = new AdventureWorks2012Context())
    {
        return processQueryable(c.SalesOrderHeaders);
    }
}

To use it you need a function to process the iqueryable as parameter, in this case it returns a DataSourceResult:

public JsonResult Post([DataSourceRequest] DataSourceRequest request)
{
    DataSourceResult sales = salesService.GetSales<DataSourceResult>
           (headersQuery=>headersQuery.ToDataSourceResult(request));
 
    return Json(sales , JsonRequestBehavior.AllowGet);
}
0
Georgi
Telerik team
answered on 08 May 2018, 06:09 AM
Hello Leah,

I am glad to hear that you managed to resolve your query and thank you for sharing your solution with the community.

In case further questions related to the initial one arise at any point, you can reply to this thread.
 

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