Ninja Database Pro
Save<T>(List<T>) Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class > Save Method : Save<T>(List<T>) Method
Save an object list to the database in an implicit transaction. If there is a problem saving any object, the implicit transation will be automatically rolled back. To save child or parents seperately, define relationships as atributes. The object must have a primary key property of Id or ObjectNameId as a type of long or an exception will be thrown. Example primary keys: Id or CustomerId If IsDeleted is defined, the object will be deleted from the datbase. If the primary is zero, the object will be inserted. If the primary key is greater than zero the object will be updated. If IsDeleted is defined and it is true, the item will be deleted. If IsDirty is defined and it is true, the item will be saved. IsDirty will be set to false after the save. If IsDirty is not defined, the item will be saved.
Syntax
Public Overloads Function Save(Of T As {Class, New})( _
   ByVal list As List(Of T) _
) As List(Of T)
Dim instance As NinjaDbPro
Dim list As List(Of T)
Dim value As List(Of T)
 
value = instance.Save(Of T)(list)
public List<T> Save<T>( 
   List<T> list
)
where T: class, new()
public:
List<T^>^ Savegeneric<typename T>
( 
   List<T^>^ list
) 
where T: ref class, gcnew()

Parameters

list

Type Parameters

T
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();
             
            List<Person> persons = new List<Person>();
            Person person1 = new Person();
            person1.DateCreated = DateTime.Now;
            person1.Name = "Greg1";
            persons.Add(person1);
             
            Person person2 = new Person();
            person2.DateCreated = DateTime.Now;
            person2.Name = "Greg2";
            persons.Add(person2);
             
            //Save the entire list as seperate records in the persons table
            //This is wrapped in an implicit transaction, if any record fails it will all roll back
            db.Save(persons);
             
            List<Person> personsCopy = db.LoadAll<Person>();
             
            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 persons As New List(Of Person)()
            Dim person1 As New Person()
            person1.DateCreated = Date.Now
            person1.Name = "Greg1"
            persons.Add(person1)
             
            Dim person2 As New Person()
            person2.DateCreated = Date.Now
            person2.Name = "Greg2"
            persons.Add(person2)
             
            'Save the entire list as seperate records in the persons table
            'This is wrapped in an implicit transaction, if any record fails it will all roll back
            db.Save(persons)
             
            Dim personsCopy As List(Of Person) = db.LoadAll(Of Person)()
             
            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
Overload List