title: Firebase Database Rest Api: How to get the next page when use LimitToLast()
body: <p>I have asked several questions about the use of <code>LimitToLast()</code> And <code>EndAt()</code> Also The Paginating backward from the end of The Data, Because I am trying to fetch the first 10 most viewed data using <code>OrderBy(&quot;Views&quot;)</code> Then Get the other 10 When Scroll Down.</p>
  <p>When fetching the first 10 data Ordered By <strong>Views</strong>, I get it correctly, but <strong>my problem</strong> is how do I get the <strong>Correct Node</strong> so as I can use it to get the (Previous Page) which contains the other 10 data
  without any problem even if there are nodes with the same value of Views.</p>
  <p>As it is assumed that we have to get the node that has the lowest value of Views and store it in <code>string</code> and when fetching the other 10 data we use it like this :
  <code>OrderBy(&quot;Views&quot;).LimitToLast(11).EndAt(LastValue,LastId)</code>
  But I always get incorrect and often duplicate results, especially if there is data with the same value of Views.
  <a href="https://ameen-66522.firebaseio.com/Education/.json?print=pretty&amp;orderBy=%22Views%22" rel="nofollow noreferrer">My Json Stracture 30 Nodes</a> :</p>
  <pre><code>{
    &quot;-Mps4qWpgU-L5E3OfAMD&quot; : {
      &quot;Text&quot; : 1,
      &quot;Views&quot; : 20
    },
    &quot;-Mps4qoSPhzh3Hzu1i2y&quot; : {
      &quot;Text&quot; : 2,
      &quot;Views&quot; : 20
    },
    &quot;-Mps4qxhzwbQ80snD3jF&quot; : {
      &quot;Text&quot; : 3,
      &quot;Views&quot; : 20
    },
    &quot;-Mps4r60gkcsFjI33d-q&quot; : {
      &quot;Text&quot; : 4,
      &quot;Views&quot; : 20
    },
    &quot;-Mps4rF4Ku1X1FIyR0M8&quot; : {
      &quot;Text&quot; : 5,
      &quot;Views&quot; : 20
    }
   More...
  }
  </code></pre>
  <p>My C# Code:</p>
  <pre><code>    public class PostData
      {
          public int Views{get;set;}
          public string Text{get;set;}
      }
  //Get First 10
  var Data = await firebaseclient
                  .Child(&quot;Education/&quot;)
                  .OrderBy(&quot;Views&quot;)
                  .LimitToLast(10)
                  .OnceAsync&lt;PostData&gt;();
                  //Order The Data By Descending on their Views And Key
                  var sortedData = Data.OrderByDescending(x=&gt;x.Object.Views).ThenByDescending(x=&gt;x.Key);
                  //Save The Last Id (lowest value of Views) and his Value Of Views
                 string LastID = sortedData.Last().Key;
                 int LastValue = sortedData.Last().Object.Views;
  
  //Get More (Previous Page)
  var Data = await firebaseclient
                  .Child(&quot;Education/&quot;)
                  .OrderBy(&quot;Views&quot;)
                  .EndAt(LastValue,LastID)
                  .LimitToLast(11)
                  .OnceAsync&lt;PostData&gt;();
                  //Order The Data By Descending on their Views And Key
                  var sortedData = Data.OrderByDescending(x=&gt;x.Object.Views).ThenByDescending(x=&gt;x.Key);
                  //Update The Last Id and his Value Of Views
                 string LastID = sortedData.Last().Key;
                 int LastValue = sortedData.Last().Object.Views;
  </code></pre>
  <p>Thanks in advance and sorry for the long post :)</p>