Ninja Database Pro
LoadPageByIndex<T> Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class : LoadPageByIndex<T> Method
The name of the index
The page number starting at 1
The number of items to return per page
If true it is sorted in ascending order
Load a page of items, sorted by the specified index. Only records that match the index value will be loaded.
Syntax
Public Function LoadPageByIndex(Of T As {Class, New})( _
   ByVal indexName As String, _
   ByVal pageNumber As Integer, _
   ByVal pageSize As Integer, _
   ByVal ascending As Boolean _
) As List(Of T)
Dim instance As NinjaDbPro
Dim indexName As String
Dim pageNumber As Integer
Dim pageSize As Integer
Dim ascending As Boolean
Dim value As List(Of T)
 
value = instance.LoadPageByIndex(Of T)(indexName, pageNumber, pageSize, ascending)
public List<T> LoadPageByIndex<T>( 
   string indexName,
   int pageNumber,
   int pageSize,
   bool ascending
)
where T: class, new()
public:
List<T^>^ LoadPageByIndexgeneric<typename T>
( 
   String^ indexName,
   int pageNumber,
   int pageSize,
   bool ascending
) 
where T: ref class, gcnew()

Parameters

indexName
The name of the index
pageNumber
The page number starting at 1
pageSize
The number of items to return per page
ascending
If true it is sorted in ascending order

Type Parameters

T

Return Value

A list of items
Example
NinjaDbPro db = new NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName");
             
//Licensed Mode
//db.UserName = "John Smith 101224";
//db.LicenseKey = "aousdf832jasf==";
 
//Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
//db.Storage = new MemoryDatabase(); //In memory database
//db.Storage = new FileDatabase();  
 
db.OpenDatabase();
 
db.AddIndex<Person>("DateCreated","DateCreated",IndexStyle.NonUnique);
List<Person> persons = new List<Person>();
Person person1 = new Person();
person1.DateCreated = DateTime.Today;
person1.Name = "Greg1";
persons.Add(person1);
 
Person person2 = new Person();
person2.DateCreated = DateTime.Today.AddMilliseconds(-1);
person2.Name = "Greg2";
persons.Add(person2);
 
db.Save(persons);
 
List<Person> page1 = db.LoadPageByIndex<Person>("DateCreated",1,1,true);
 
//Person2 should be loaded first because the date is less than Person1
List<Person> page2 = db.LoadPageByIndex<Person>("DateCreated", 2, 1, true);
 
db.CloseDatabase();
Dim db As New NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName")
 
'Licensed Mode
'db.UserName = "John Smith 101224";
'db.LicenseKey = "aousdf832jasf==";
 
'Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
'db.Storage = new MemoryDatabase(); //In memory database
'db.Storage = new FileDatabase();  
 
db.OpenDatabase()
 
db.AddIndex(Of Person)("DateCreated","DateCreated",IndexStyle.NonUnique)
Dim persons As New List(Of Person)()
Dim person1 As New Person()
person1.DateCreated = Date.Today
person1.Name = "Greg1"
persons.Add(person1)
 
Dim person2 As New Person()
person2.DateCreated = Date.Today.AddMilliseconds(-1)
person2.Name = "Greg2"
persons.Add(person2)
 
db.Save(persons)
 
Dim page1 As List(Of Person) = db.LoadPageByIndex(Of Person)("DateCreated",1,1,True)
 
'Person2 should be loaded first because the date is less than Person1
Dim page2 As List(Of Person) = db.LoadPageByIndex(Of Person)("DateCreated", 2, 1, True)
 
db.CloseDatabase()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NinjaDbPro Class
NinjaDbPro Members