Example #1
0
        private void DoReadWork(UnitOfWork uow, int index)
        {
            var items = uow.Context.From<Warrior>()
                .Map(w => w.ID)
                .Map(w => w.Name)
                .Join<Armour>((a, w) => a.WarriorID == w.ID)
                .Join<ArmourPart>((ap, a) => ap.ID == a.ArmourPartID)
                .Join<Weapon, Warrior>((w, wa) => w.ID == wa.WeaponID)
                .For<WarriorWithArmour>()
                .Map<Weapon>(w => w.Name, wa => wa.WeaponName)
                .Map<Armour>(a => a.Name, wa => wa.ArmourName)
                .Select();

            WriteLog(index, items.Count());
        }
Example #2
0
        public void Work()
        {
            // this method shows how the
            _log = new List<string>();
            int count = 100;

            DatabaseManager.CreateDatabase();

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var provider = new SqliteContextProvider(DatabaseManager.ConnectionString);
            using (var context = provider.Open())
            {
                using (var uow = new UnitOfWork(context))
                {
                    for (int i = 0; i < count; i++)
                    {
                        DoReadWork(uow, i);
                    }
                }
            }

            stopwatch.Stop();
            _log.Add(string.Format("Creating one context for {0} selects calls took {1} ms", count, stopwatch.ElapsedMilliseconds));

            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < count; i++)
            {
                using (var uow = new UnitOfWork(DatabaseManager.ConnectionString))
                {
                    DoReadWork(uow, i);
                }
            }

            stopwatch.Stop();
            _log.Add(string.Format("Creating a context per call for {0} selects calls took {1} ms", count, stopwatch.ElapsedMilliseconds));

            PrintLog();
        }