Ninja Database Pro
Pack Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class : Pack Method
Reclaim the space from previously deleted and updated items
Syntax
Public Function Pack() As Long
Dim instance As NinjaDbPro
Dim value As Long
 
value = instance.Pack()
public long Pack()
public:
int64 Pack(); 

Return Value

The number of bytes reclaimed
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();
             
            long startSize = db.DataFileSize;
             
            Person person1 = new Person();
            person1.DateCreated = DateTime.Now;
            person1.Name = "Greg1";
            db.Save(person1);
             
            Person person2 = new Person();
            person2.DateCreated = DateTime.Now;
            person2.Name = "Greg2";
            db.Save(person2);
             
            long savedSize = db.DataFileSize;
             
            //Delete should not change the size
            db.Delete<Person>(person1.PersonId);
            db.Delete<Person>(person2.PersonId);
             
            long deletedSize = db.DataFileSize;
             
            //Pack it
            long packSavings = db.Pack();
             
            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()
             
            Dim startSize As Long = db.DataFileSize
             
            Dim person1 As New Person()
            person1.DateCreated = Date.Now
            person1.Name = "Greg1"
            db.Save(person1)
             
            Dim person2 As New Person()
            person2.DateCreated = Date.Now
            person2.Name = "Greg2"
            db.Save(person2)
             
            Dim savedSize As Long = db.DataFileSize
             
            'Delete should not change the size
            db.Delete(Of Person)(person1.PersonId)
            db.Delete(Of Person)(person2.PersonId)
             
            Dim deletedSize As Long = db.DataFileSize
             
            'Pack it
            Dim packSavings As Long = db.Pack()
             
            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