Paging implementation using some common query and different select clause

May 10, 2013 at 4:56 AM
Hi,
Please see below function in which i have been making a use of DynaSQL framework.

*******************Function (VB.Net) *****************************************************************
Public Overloads Function GetConfiscatedMembersList() As List(Of bMemberMst)
     Try
         m_dbQuery = DBQuery.SelectAll() _
         .TopRange(MyBase.PagingInfo.PageSize *(MyBase.PagingInfo.CurrentPage - 1), MyBase.PagingInfo.PageSize) _
         .From(Database.Tables.EMEMBER_MST.ToString()) _
         .Where(Database.Tables.EMEMBER_MST.Columns.C_IS_CONFISCATED.ToString, Data.Compare.Equals, DBConst.String("1")) _
         .AndWhere(Database.Tables.EMEMBER_MST.Columns.C_STATUS.ToString, Data.Compare.Equals, DBConst.String(CByte(Gspl.Enumerations.Definations.DB_Status.Active).ToString()))

         m_ListOfT = Database.Tables.EMEMBER_MST.Rows.ToCollection(Of bMemberMst)(m_dbQuery)


         '--Set Paging Details.-------------------------------------------------------------------------------------------------------------------------------------------------------------
         If MyBase.PagingInfo.PageSize > 0 Then
             m_dbQuery = DBQuery.SelectCount() _
             .From(Database.Tables.EMEMBER_MST.ToString()) _
             .Where(Database.Tables.EMEMBER_MST.Columns.C_IS_CONFISCATED.ToString,Data.Compare.Equals, DBConst.String("1")) _
            .AndWhere(Database.Tables.EMEMBER_MST.Columns.C_STATUS.ToString,Data.Compare.Equals,DBConst.String(CByte(Gspl.Enumerations.Definations.DB_Status.Active).ToString()))
              CountTotalPages(m_dbQuery)
         End If
        '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

         Return m_ListOfT
     Catch ex As Exception
         Throw ex
     End Try
End Function

I need to use paging based on some user preferences. Here you can see that only different ce between the two queries is,

DBQuery.SelectAll() _
.TopRange(MyBase.PagingInfo.PageSize *(MyBase.PagingInfo.CurrentPage - 1), MyBase.PagingInfo.PageSize)

And

DBQuery.SelectCount()

So, as of now you can see the query is same starting from "From" clause. Only the above part differs. So, is there any way to achieve the thing in some graceful way, instead of duplicating the query 2 times?

Thanks in advance..!!