Esempio n. 1
0
        private static async Task InitAsync()
        {
            database = new SQLiteAsyncConnection(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "db.db"));


            await database.DropTableAsync <FirstEntity>();

            await database.DropTableAsync <SecondEntity>();

            await database.CreateTableAsync <FirstEntity>();

            await database.CreateTableAsync <SecondEntity>();

            var fe1 = new FirstEntity {
                Name = "Jack"
            };
            var fe2 = new FirstEntity {
                Name = "Marc"
            };
            var fe3 = new FirstEntity {
                Name = "Thomas"
            };
            var fe4 = new FirstEntity {
                Name = "John"
            };


            var se1 = new SecondEntity {
                Name = "Jesica"
            };
            var se2 = new SecondEntity {
                Name = "Tom"
            };
            var se3 = new SecondEntity {
                Name = "Jerru"
            };

            await database.InsertAsync(fe1);

            await database.InsertAsync(fe2);

            await database.InsertAsync(fe3);

            await database.InsertAsync(fe4);

            await database.InsertAsync(se1);

            await database.InsertAsync(se2);

            await database.InsertAsync(se3);
        }
        public void MainTest()
        {
            using (Session session = Domain.OpenSession()) {
                using (TransactionScope transactionScope = session.OpenTransaction()) {
                    // Creating new persistent object
                    var first = new FirstEntity(session)
                    {
                        Text = "first!"
                    };

                    // Creating new persistent object
                    var second = new SecondEntity(session)
                    {
                        Text = "second!"
                    };

                    new FirstChild(session, first)
                    {
                        Text = "First"
                    };
                    new SecondChild(session, second)
                    {
                        Text = "Second"
                    };

                    // Committing transaction
                    transactionScope.Complete();
                }
            }

            using (Session session = Domain.OpenSession()) {
                using (TransactionScope transactionScope = session.OpenTransaction()) {
                    Console.WriteLine(session.Query.All <SecondChild>().First().Text);
                    Console.WriteLine(session.Query.All <FirstChild>().First().Text);
                }
            }
        }
Esempio n. 3
0
 private static void RunSecondEntityCUI(IAccessor <SecondEntity> accessor)
 {
     Console.WriteLine("Commands:\np - print all\np [id] - print one\ni [id] - insert with id\nd [id] - delete by id\nx - quit");
     Console.WriteLine("Now using accessor: {0} ", accessor.GetType().Name);
     while (true)
     {
         string[] command = Console.ReadLine().Split(' ', ',');
         if (command[0] == "p")
         {
             Stopwatch s = new Stopwatch();
             s.Start();
             if (command.Length == 1)
             {
                 foreach (SecondEntity p in accessor.GetAll())
                 {
                     Console.WriteLine(p);
                 }
             }
             else if (command.Length == 2)
             {
                 string       id = command[1];
                 SecondEntity p  = accessor.GetById(id);
                 Console.WriteLine(p.ToString());
             }
             s.Stop();
             Console.WriteLine("Complete! elapsed: {0}ms", s.ElapsedMilliseconds);
         }
         else if (command[0] == "d")
         {
             Stopwatch s = new Stopwatch();
             s.Start();
             int id = Int32.Parse(command[1]);
             accessor.DeleteById(id);
             s.Stop();
             Console.WriteLine("Complete! elapsed: {0}ms", s.ElapsedMilliseconds);
         }
         else if (command[0] == "i")
         {
             Stopwatch s = new Stopwatch();
             s.Start();
             string       id = command[1];
             SecondEntity p  = new SecondEntity()
             {
                 Field = id
             };
             if (command.Length >= 3)
             {
                 p.UnattributeField = command[2];
             }
             accessor.Insert(p);
             s.Stop();
             Console.WriteLine("Complete! elapsed: {0}ms", s.ElapsedMilliseconds);
         }
         else if (String.IsNullOrEmpty(command[0]) || command[0] == "x")
         {
             break;
         }
         else
         {
             Console.WriteLine("Unknown command");
         }
     }
 }