Ejemplo n.º 1
0
        // #end example

        private void storeInitialObjects(DatabaseSupportWithReadWriteLock dbSupport)
        {
            dbSupport.InWriteTransaction(
                container =>
            {
                container.Store(new Person("Joe"));
                container.Store(new Person("Jan"));
                container.Store(new Person("Joanna"));
                container.Store(new Person("Phil"));
            });
        }
Ejemplo n.º 2
0
 // #example: Use a read transaction for reading objects
 private void ListAllPeople(DatabaseSupportWithReadWriteLock dbSupport)
 {
     dbSupport.InReadTransaction(
         container =>
     {
         var result = from Person p in container select p;
         foreach (Person person in result)
         {
             Console.WriteLine(person.Name);
         }
     });
 }
Ejemplo n.º 3
0
        // #end example

        // #example: Use a write transaction to update objects
        private void UpdateAllJoes(DatabaseSupportWithReadWriteLock dbSupport)
        {
            dbSupport.InWriteTransaction(
                container =>
            {
                var allJoes = from Person p in container
                              where p.Name == "Joe"
                              select p;
                foreach (Person joe in allJoes)
                {
                    joe.Name = "New Joe";
                    container.Store(joe);
                }
            });
        }
Ejemplo n.º 4
0
        public void Main()
        {
            using (var database = new DatabaseSupportWithReadWriteLock(Db4oEmbedded.OpenFile("database.db4o")))
            {
                storeInitialObjects(database);

                // Schedule back-ground tasks
                Action <DatabaseSupportWithReadWriteLock> toRun = UpdateAllJoes;
                var waitHandle = toRun.BeginInvoke(database, null, null);

                // While doing other work
                ListAllPeople(database);

                // Wait for the task to finish
                toRun.EndInvoke(waitHandle);
            }
        }