2009-01-28

Dynamic LINQ Gridview Custom Paging

請參考
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

首先把DynamicLinq.vb加到App_Code內
引用

Imports System.Linq.Dynamic
Imports System.Linq.Expressions

<DataObjectMethod(DataObjectMethodType.Select, False)> _
Public Function GetOrgAllData(ByVal startRowIndex As Integer, _
ByVal maximumRows As Integer, _
ByVal sortExpression As String) As IEnumerable(Of Organization)
'If sortExpression = "" Then sortExpression = "OrganizationsID"
Dim tbl As New DataClassesDataContext
Dim query = tbl.Organizations _
.OrderBy(IIf(sortExpression = "", "OrganizationsID", sortExpression)) _
.Skip(startRowIndex) _
.Take(maximumRows)
Return query
End Function

<DataObjectMethod(DataObjectMethodType.Select, False)> _
Public Function GetOrgAllDataCount() As Integer
Dim tbl As New DataClassesDataContext
Return tbl.Organizations.Count
End Function

0 comments: