Ninja Database Pro
Truncate<T> Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class : Truncate<T> Method
Delete all objects of a specific type
Syntax
Public Function Truncate(Of T As {Class, New})() As Integer
Dim instance As NinjaDbPro
Dim value As Integer
 
value = instance.Truncate(Of T)()
public int Truncate<T>()
where T: class, new()
public:
int Truncategeneric<typename T>
(); 
where T: ref class, gcnew()

Type Parameters

T

Return Value

The number of items deleted
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();
             
            Person person1 = new Person();
            person1.DateCreated = DateTime.Now.AddDays(-1);
            person1.Name = "Greg1";
            db.Save(person1);
             
            Person person2 = new Person();
            person2.DateCreated = DateTime.Now.AddDays(-2);
            person2.Name = "Greg2";
            db.Save(person2);
             
            Person person3 = new Person();
            person3.DateCreated = DateTime.Now.AddDays(-3);
            person3.Name = "Greg3";
            db.Save(person3);
             
            //Delete all persons
            db.Truncate<Person>();
             
            //Reclaim the space used by the persons table
            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 person1 As New Person()
            person1.DateCreated = Date.Now.AddDays(-1)
            person1.Name = "Greg1"
            db.Save(person1)
             
            Dim person2 As New Person()
            person2.DateCreated = Date.Now.AddDays(-2)
            person2.Name = "Greg2"
            db.Save(person2)
             
            Dim person3 As New Person()
            person3.DateCreated = Date.Now.AddDays(-3)
            person3.Name = "Greg3"
            db.Save(person3)
             
            'Delete all persons
            db.Truncate(Of Person)()
             
            'Reclaim the space used by the persons table
            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