NinjaDbPro db = new NinjaDbPro("SingleIndexExampleDir", "SingleIndexExampleDir.db");
//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();
//Open the database
db.OpenDatabase();
//Add a single property index if it doesn't already exist
if (!db.IndexExists<Person>("NameIndex"))
db.AddIndex<Person,string>("NameIndex", "Name", IndexStyle.NonUnique);
//Add a record to the database
Person person = new Person();
person.Name = "John Smith";
person.DateCreated = DateTime.Now;
db.Save(person);
//Find an exact matach. If the index is unique, this is the fastest.
var exactQuery = db.CreateIndexQuery<Person, string>("NameIndex", "John Smith");
//Lazy load the first record and write out a property
Console.WriteLine(exactQuery[0].LazyValue.DateCreated);
//Find a partial match
var partialQuery = db.CreateIndexQuery<Person, string>("NameIndex").Where(o => o.Index.StartsWith("John"));
//Write the DateCreated for all records that have a name beginning with John
foreach (var indexRecord in partialQuery)
{
Console.WriteLine(indexRecord.LazyValue.DateCreated);
}
//Close the database
db.CloseDatabase();