public static MarcelloDB.Session CreateSession() { var platform = new MarcelloDB.netfx.Platform(); var session = new MarcelloDB.Session(platform, @"."); return(session); }
public DBLayer() { // Get the platform object for the database IPlatform platform = new MarcelloDB.netfx.Platform(); // Getting the Personal Special Folder. The database will go here. var dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Creating a database session var session = new MarcelloDB.Session(platform, dataPath); // Getting a collections file. Each collection in the file is a database table var expensesFile = session["expenses.dat"]; // getting the meta data (count of records) from the meta data file var expensesMetaDataFile = session["expensesMetaData.dat"]; // Getting the expenses table and mapping how it will be given an ID (The expense time stamp) _expensesCollection = expensesFile.Collection <Expense, int>("expenses", e => e.ID); // Getting the meta data table _metaDataCollection = expensesMetaDataFile.Collection <MetaData, String>("metaData", e => e.Name); // does this table have an auto incrementing key? if (!DataBaseInitialized()) { _expensesCount = new MetaData("expenses:count", 0); _metaDataCollection.Persist(_expensesCount); } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += this.OnSuspending; var dataFolderPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path; var session = new MarcelloDB.Session(new Platform(), dataFolderPath); var collection = session["data"].Collection <Article, int, ArticleIndex>("articles", a => a.ID); for (int i = 0; i < 1000; i++) { collection.Persist(new Article { ID = i, Name = string.Format("Article_{0}", i) }); } for (int i = 0; i < 1000; i++) { var article = collection.Find(i); System.Diagnostics.Debug.Assert(article != null); } foreach (var article in collection.Indexes.Name.Between("Article_110").And("Article_120")) { System.Diagnostics.Debug.Assert(article != null); } System.Diagnostics.Debug.Assert( collection.Indexes.Name.Between("Article_110").AndIncluding("Article_120").Count() == 11 ); }
static void Main(string[] args) { var platform = new Platform(); var dataPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); //This code is platform independent so we can implement this in shared code. // Injecting the platform here // || var session = new MarcelloDB.Session(platform, dataPath); var personsFile = session["persons.dat"]; var personsCollection = personsFile.Collection <Person, string>("persons", p => p.Id); var jonSnow = new Person { Id = "123", FirstName = "Jon", Surname = "Snow", Addresses = new List <Address> { new Address { City = "Castle Black" }, new Address { City = "Winterfell" }, } }; personsCollection.Persist(jonSnow); var foundJon = personsCollection.Find("123"); Console.WriteLine("Found Jon"); }
protected RepositoryBase() { _session = DependencyService.Get <IPlatformFactory>().GetSession(); _collection = GetCollection(); }
protected RepositoryBase(IPlatformFactory platformFactory) { _session = platformFactory.GetSession(); _collection = GetCollection(); }