7 Answers, 1 is accepted
0
Hi mary,
It depends on what you mean by "best" method :)
If your data comes from a storage with a full blown LINQ provider (Entity Framework, Linq2Sql, OpenAccess) you can benefit from the grid's built-in expression engine which will access your data in the most optimal way. All queries (for paging, sorting, filtering) will be executed at the database layer (read run on the DB server).
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
It depends on what you mean by "best" method :)
If your data comes from a storage with a full blown LINQ provider (Entity Framework, Linq2Sql, OpenAccess) you can benefit from the grid's built-in expression engine which will access your data in the most optimal way. All queries (for paging, sorting, filtering) will be executed at the database layer (read run on the DB server).
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
mary
Top achievements
Rank 1
answered on 08 Jan 2010, 09:31 PM
Hi,
Thanks. I think i see what you are saying. I guess I was talking best in terms of performance if you have a lot of data to bring back and filter. So when the grid is first loaded, we would have 250,000+ rows that would be brought back from a Linq query. I'm thinking this would be rather slow to load? Do all rows get loaded or just the first page? What binding method would be best in this case, Server, Ajax, Custom? Thanks again.
Thanks. I think i see what you are saying. I guess I was talking best in terms of performance if you have a lot of data to bring back and filter. So when the grid is first loaded, we would have 250,000+ rows that would be brought back from a Linq query. I'm thinking this would be rather slow to load? Do all rows get loaded or just the first page? What binding method would be best in this case, Server, Ajax, Custom? Thanks again.
0
Joshua Holt
Top achievements
Rank 2
answered on 08 Jan 2010, 10:38 PM
Hi Mary,
When you bind your datasource to the grid, the grid api will query the datasource via linq to grab only records for the first page, so if you set page size to 10 it will query the datasource for the first 10, if you set it to 50, it will grab the first 50, and so on. On page 2 it will query for the next N records. (.Skip((page-1)*pageSize).Take(pageSize) basically).
If you bind the grid to your direct Linq IQueryable<> you have been building, then all of the above will take place at the database layer. If you have done anything like called .ToList(), .Count() or any of that on your Linq expression, then the above will take place in the view. The latter would be quite a bit slower than letting the grid handle when to execute the query. This also applies to using the grid filters.
The best bet would be to build your linq query, and pass it to the view, and bind to grid as IQueryable<>, then the grid can add its parameters on, and execute the linq expression, and the full expression will be executed in the DB layer.
-Josh
When you bind your datasource to the grid, the grid api will query the datasource via linq to grab only records for the first page, so if you set page size to 10 it will query the datasource for the first 10, if you set it to 50, it will grab the first 50, and so on. On page 2 it will query for the next N records. (.Skip((page-1)*pageSize).Take(pageSize) basically).
If you bind the grid to your direct Linq IQueryable<> you have been building, then all of the above will take place at the database layer. If you have done anything like called .ToList(), .Count() or any of that on your Linq expression, then the above will take place in the view. The latter would be quite a bit slower than letting the grid handle when to execute the query. This also applies to using the grid filters.
The best bet would be to build your linq query, and pass it to the view, and bind to grid as IQueryable<>, then the grid can add its parameters on, and execute the linq expression, and the full expression will be executed in the DB layer.
-Josh
0
mary
Top achievements
Rank 1
answered on 11 Jan 2010, 10:01 PM
Hi, Thanks that was helpful. So is it possible to build a comparable linq query to pass to the view with nhibernate? So that it would yield the same results where everything is happeningn on the DB layer?
Thanks again.
Thanks again.
0
Sunitha
Top achievements
Rank 1
answered on 18 Jan 2011, 09:15 PM
We are using the Telerik Grid which works fine when our database has 30,000 records or so.
When the load increases to 700K records, it returns a timeout. We followed some other threads
in this forum and ensure that we return a IQueryable to the Grid which means that it should return
only the 20 records to the Grid no matter what the size of the db is. But in spite of that, the Grid
breaks when the record count is 700 K. We are using LINQ. I have attached portion of our code
Please suggest a fix when large amounts of data is involved
[GridAction]
public ActionResult _CheckBoxesSongGrid(int workflowStatus)
{
var adminQueueByStatus = _repository.AdminQueueByStatus(workflowStatus);
return View(new GridModel(adminQueueByStatus));
}
DB call........
/* ----------------------------------------------------------------------------
* list of songs in an admin queue by status
* ----------------------------------------------------------------------------
*/
public IQueryable<vwLstUserSongAssignment> AdminQueueByStatus(int statusID)
{
return dbMusicLicensor.vwLstUserSongAssignments.Where(p => p.workflow_status_id == statusID);
}
View.......
<div id="rhAdminInProgress">
<%
int[] checkedRecordsInProgress = (int[])ViewData["checkedRecordsInProgress"];
Html.Telerik().Grid<vwLstUserSongAssignment>()
.Name("InProgressGrid")
.Columns(columns =>
{
columns.Bound(o => o.user_track_assignment_id)
.ClientTemplate("<input type='checkbox' name='checkedRecordsInProgress' value='<#= user_track_assignment_id #>' />")
.Title(strings.ID_25)
.Width(50)
.HtmlAttributes(new { style = "text-align:center" });
columns.Bound(o => o.user_track_assignment_id).Title(strings.ID_18).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.track_title).Title(strings.ID_19).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.artist_name).Title(strings.ID_8).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.full_name).Title(strings.ID_20).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.workflow_status_descr).Width(70).Title(strings.ID_22).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.deadline_date).Format("{0:MM/dd/yyyy}").Title(strings.ID_28).HtmlAttributes(new { style = "font-weight:normal" });
})
.Selectable()
.Sortable()
.Resizable(resizing => resizing.Columns(true))
.ClientEvents(events => events
.OnRowSelect("onRowSelect_AdminQueueGrid"))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("_CheckBoxesSongGrid", "RightsToolSvc", new { workflowStatus = CONSTANTS.WORKFLOWINPROGRESS }))
.Pageable(pager => pager.PageSize(20).Style(GridPagerStyles.PageInput | GridPagerStyles.NextPrevious)
.Position(GridPagerPosition.Both))
.Render();
%>
When the load increases to 700K records, it returns a timeout. We followed some other threads
in this forum and ensure that we return a IQueryable to the Grid which means that it should return
only the 20 records to the Grid no matter what the size of the db is. But in spite of that, the Grid
breaks when the record count is 700 K. We are using LINQ. I have attached portion of our code
Please suggest a fix when large amounts of data is involved
[GridAction]
public ActionResult _CheckBoxesSongGrid(int workflowStatus)
{
var adminQueueByStatus = _repository.AdminQueueByStatus(workflowStatus);
return View(new GridModel(adminQueueByStatus));
}
DB call........
/* ----------------------------------------------------------------------------
* list of songs in an admin queue by status
* ----------------------------------------------------------------------------
*/
public IQueryable<vwLstUserSongAssignment> AdminQueueByStatus(int statusID)
{
return dbMusicLicensor.vwLstUserSongAssignments.Where(p => p.workflow_status_id == statusID);
}
View.......
<div id="rhAdminInProgress">
<%
int[] checkedRecordsInProgress = (int[])ViewData["checkedRecordsInProgress"];
Html.Telerik().Grid<vwLstUserSongAssignment>()
.Name("InProgressGrid")
.Columns(columns =>
{
columns.Bound(o => o.user_track_assignment_id)
.ClientTemplate("<input type='checkbox' name='checkedRecordsInProgress' value='<#= user_track_assignment_id #>' />")
.Title(strings.ID_25)
.Width(50)
.HtmlAttributes(new { style = "text-align:center" });
columns.Bound(o => o.user_track_assignment_id).Title(strings.ID_18).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.track_title).Title(strings.ID_19).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.artist_name).Title(strings.ID_8).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.full_name).Title(strings.ID_20).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.workflow_status_descr).Width(70).Title(strings.ID_22).HtmlAttributes(new { style = "font-weight:normal" });
columns.Bound(o => o.deadline_date).Format("{0:MM/dd/yyyy}").Title(strings.ID_28).HtmlAttributes(new { style = "font-weight:normal" });
})
.Selectable()
.Sortable()
.Resizable(resizing => resizing.Columns(true))
.ClientEvents(events => events
.OnRowSelect("onRowSelect_AdminQueueGrid"))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("_CheckBoxesSongGrid", "RightsToolSvc", new { workflowStatus = CONSTANTS.WORKFLOWINPROGRESS }))
.Pageable(pager => pager.PageSize(20).Style(GridPagerStyles.PageInput | GridPagerStyles.NextPrevious)
.Position(GridPagerPosition.Both))
.Render();
%>
0
Joshua Holt
Top achievements
Rank 2
answered on 19 Jan 2011, 05:44 PM
Hi Sunitha,
Any chance you can open Sql Profiler, and post the query that is being run. If you don't have Sql profiler, you can get a free version from: http://sites.google.com/site/sqlprofiler/. Once I see the query, I will have a better understanding about what is happening. I have bound the grid to over 1 million records in the past, and it worked flawlessly :)
Regards,
Josh
Any chance you can open Sql Profiler, and post the query that is being run. If you don't have Sql profiler, you can get a free version from: http://sites.google.com/site/sqlprofiler/. Once I see the query, I will have a better understanding about what is happening. I have bound the grid to over 1 million records in the past, and it worked flawlessly :)
Regards,
Josh
0
Rahul
Top achievements
Rank 1
answered on 29 Aug 2012, 07:04 AM
We have 4 different layers in our application like Services, Repository etc. We are using Entity Framework and SQL store procedure to fetch data from Database and then bind the returned data to the Telerik MVC grid. So will the above behaviour still holds good for above as well if we are going to get 300,000 records and bind those to the grid?
Rahul
Rahul