Ninja Database Pro
CreateObjectQuery<T> Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class : CreateObjectQuery<T> Method
Create a linq query based on the object type. This performs a table scan returning only items that match the query. Loading by the primary key is fastest, followed by CreateIndexQuery.
Syntax
Public Function CreateObjectQuery(Of T As {Class, New})() As ObjectQuery(Of T)
Dim instance As NinjaDbPro
Dim value As ObjectQuery(Of T)
 
value = instance.CreateObjectQuery(Of T)()
public ObjectQuery<T> CreateObjectQuery<T>()
where T: class, new()
public:
ObjectQuery<T^>^ CreateObjectQuerygeneric<typename T>
(); 
where T: ref class, gcnew()

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 = "John Smith";
            persons.Add(person1);
             
            Person person2 = new Person();
            person2.DateCreated = DateTime.Now;
            person2.Name = "Jane";
            persons.Add(person2);
             
            db.Save(persons);
             
            //Create a person object query
            ObjectQuery<Person> query = db.CreateObjectQuery<Person>();
             
            //Create a LINQ expression
            var result = from p in query
                         where p.Name == "Jane"
                         select p;
             
            //Update each Jane to Jane Smith
            foreach (Person item in result)
            {
                item.Name = "Jane Smith";
                db.Save(item);
            }
             
            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 = "John Smith"
            persons.Add(person1)
             
            Dim person2 As New Person()
            person2.DateCreated = Date.Now
            person2.Name = "Jane"
            persons.Add(person2)
             
            db.Save(persons)
             
            'Create a person object query
            Dim query As ObjectQuery(Of Person) = db.CreateObjectQuery(Of Person)()
             
            'Create a LINQ expression
            Dim result = From p In query
                         Where p.Name = "Jane"
                         Select p
             
            'Update each Jane to Jane Smith
            For Each item As Person In result
                item.Name = "Jane Smith"
                db.Save(item)
            Next item
             
            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