private static void TestMagpieDatabase() { MagpieServer server = MagpieServer.Create(@"C:\tmp"); MagpieDatabase database = server.GetDatabase("test"); MagpieCollection <Cat> catCollection = database.GetCollection <Cat>("cat"); MagpieCollection <Dog> dogCollection = database.GetCollection <Dog>("dog"); Console.WriteLine("Save One Cat"); Cat origin = new Cat() { Name = "Garfield", Legs = 4 }; catCollection.Save <Cat>(origin); Console.WriteLine("Retrieve One Cat"); Cat retrieve = catCollection.FindOneById(origin.Id); Console.WriteLine(retrieve.ToString()); Console.WriteLine("Retrieve All Cat"); foreach (var item in catCollection.FindAll()) { Console.WriteLine(item.ToString()); } Console.WriteLine("Remove One Cat"); Console.WriteLine(origin.ToString()); catCollection.Remove(origin.Id); Console.WriteLine("Retrieve All Cat"); foreach (var item in catCollection.FindAll()) { Console.WriteLine(item.ToString()); } Console.WriteLine("Remove All Cat"); catCollection.RemoveAll(); Console.WriteLine("Retrieve All Cat"); foreach (var item in catCollection.FindAll()) { Console.WriteLine(item.ToString()); } Console.WriteLine("Save One Dog"); Dog originDog = new Dog() { Name = "Spotted Dog", Legs = 4 }; dogCollection.Save <Dog>(originDog); Console.WriteLine("Retrieve One Dog"); Dog retrieveDog = dogCollection.FindOneById(originDog.Id); Console.WriteLine(retrieveDog.ToString()); }
public Database(string path, string databaseName) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (string.IsNullOrEmpty(databaseName)) { throw new ArgumentNullException("databaseName"); } _server = MagpieServer.Create(path); _database = _server.GetDatabase(databaseName); }