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

Testing Lazy Loading

7 Answers 494 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 20 Jan 2016, 10:49 PM

I've downloaded and I'm running the kendoui-northwind-dashboard-master project.

In the OrdersController I've set a breakpoint on the Orders_Read Action.

I run the application in Debug and navigate to the Products & Orders page.

In Locals I drill down into orders/Results View and it returns 830 records.

I then set the Order Date filter to 'Is after 4/22/1998'.

In Locals I again drill down into orders/Results View and it still returns 830 records.

The view properly filters and returns 34 items.

1. Is Lazy Loading being used in this Grid?

2. If so how do I verify only the filtered records are returned from the DB query?

3. If Lazy loading is not being used in this project could you point me to or supply me with one that is?

 

I need to be able to build a project that scales properly so that I can return a subset of records rather than the thousands of records that will be in the database.

 

 

 

 

 

7 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 22 Jan 2016, 11:24 AM
Hello Joe,

Please examine the following thread that discusses the functionality in more detail. Ensure that the model you are using supports IQueriable and see how the behavior changes.



Regards,
Viktor Tachev
Telerik
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
0
Joe
Top achievements
Rank 1
answered on 22 Jan 2016, 04:21 PM

Hello Viktor,

You didn't answer any of my questions.  Did you even look at Telerik.s kendoui-northwind-dashboard-master project?

In the OrdersController the private static IQueryable<OrderViewModel> GetOrders() method returns an IQueryable.

private static IQueryable<OrderViewModel> GetOrders()
{
var northwind = new NorthwindEntities();
var orders = northwind.Orders.Select(order => new OrderViewModel
{
CustomerID = order.CustomerID,
OrderID = order.OrderID,
EmployeeID = order.EmployeeID,
OrderDate = order.OrderDate,
ShipCountry = order.ShipCountry,
ShipVia = order.ShipVia,
ShippedDate = order.ShippedDate,
ShipName = order.ShipName,
ShipAddress = order.ShipAddress,
ShipCity = order.ShipCity,
ShipPostalCode = order.ShipPostalCode
});
return orders;
}

 

The Orders_Read Action uses ToDataSourceResult to return Json.

public ActionResult Orders_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(GetOrders().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

 

From what I can see it is supposed to do Lazy Loading according to the Kendo documentation referenced in the SO Link

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/ajax-binding

 

The Grid in the Products Tab of the ProductsAndOrders view uses Ajax()

.DataSource(dataSource => dataSource
   .Ajax()
    .Model(model => { model.Id(detail => detail.OrderDetailID); })
    .Events(e => e.Error(errorEvent))
     .Read("OrderDetails_Read", "OrderDetails", new { OrderID = "#=OrderID#" })
      .Update("OrderDetails_Update", "OrderDetails")
       .Create("OrderDetails_Create", "OrderDetails", new { ParentID = "#=OrderID#" })
        .Destroy("OrderDetails_Destroy", "OrderDetails")

 

But again when I set a breakpoint in the GetOrders() method and filter the OrderDate it returns all 830 records rather than 38.

 

So Please this time actually answer the questions I'm asking:

1. Is or is not the kendoui-northwind-dashboard-master project an example of Lazy Loading?

2. If it is then why is it returning all the records rather than the filtered subset?

3. Is the way I'm trying to verify the Lazy Loading correct?  If not how can I verify it?

 

Thank you,

 Joe

 

0
Viktor Tachev
Telerik team
answered on 25 Jan 2016, 02:27 PM
Hello Joe,

The project is working as described in the documentation. Only the relevant records are returned to the client. You can see that the Data property holds 20 records (the specified page size). The Total property returns only the total number or records, not actual records. This way the pager for the grid can display the correct number of pages.


Furthermore you can examine the Network tab in the browser console and see the number of items that are returned from the server.




Regards,
Viktor Tachev
Telerik
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
0
Joe
Top achievements
Rank 1
answered on 25 Jan 2016, 04:41 PM

Hello Viktor,

At no point did I question whether the Web server was returning a filtered number of records.  It obviously is.

I replicated both your screen shots but you didn't setup the filtering scenario (Order Date after or equal to 4/22/1998)

and they are both examining the Web server Client browser communication.

What I'm questioning is whether the Web server is filtering its request to the Database Server.  They are two separate servers and communicate across an intranet or over the internet.

As I pointed out in my posts that does not appear to be happening,  all 830 records are appearing to be returned from the Database.

Please setup the filter condition and put a breakpoint on the 'return orders' line of the 'private static IQueryable<OrderViewModel> GetOrders()' method in the  Orders Controller.  Then expand the Results View of the query, it returns all 830 records. That is placing a large load on the database server and the intranet/internet.  If the filter parameters are not passed to the query that is not scalable.

Please examine the communication between the Web server and the Database Server and NOT between the WebServer and Client Browser.  The latter is working and is not in question.

After you have done this please let me know if I'm either correct or misinterpreting.

Thank you,

Joe

 

 

0
Accepted
Viktor Tachev
Telerik team
answered on 26 Jan 2016, 03:37 PM
Hi Joe,

Note that the query to the SQL server is not executed in the GetOrders() method. The orders collection shows the total number of records in the data source, however, they are not returned from the database.

You can check this by running SQL Server Profiler. In it you can see that the query that is sent to the database server is "select top 20...".​

If you would like additional information on when queries are executed you will find the following article interesting.



Regards,
Viktor Tachev
Telerik
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
0
Joe
Top achievements
Rank 1
answered on 26 Jan 2016, 09:20 PM

Finally you answered my questions.  Thank you.

Two notes:

The number of rows retrieved is determined by the PageSize, which is 20 by default.

When in debug if you expand a Results View it will, as it says, enumerate the IEnumerable, which pulls back all the records.

Thank you,

Joe

 

 

0
Viktor Tachev
Telerik team
answered on 27 Jan 2016, 02:01 PM
Hi Joe,

Your observations are correct the number of retrieved items depends on the page size. For example if the PageSize is set to 35 the query will look like "select top 35...".

Also, when expanding the results view in debug mode you would manually trigger a query that request all items.

Regards,
Viktor Tachev
Telerik
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
Tags
General Discussions
Asked by
Joe
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Joe
Top achievements
Rank 1
Share this question
or