コード例 #1
0
        public void ReadFromDatabase(Levels context)
        {
            lock (readSynchronization)
            {
                // The Read operation will always modify data to lock, so that other connections block until the transaction is committed.
                // See/run unit tests if changing, i.e. test Performance_Identities_Stored_In_The_Database_Concurrent_Access.

                foreach (var item in identities.Keys.ToList())
                {
                    if (!context.Identities.Any(t => t.Id == item))
                    {
                        identities[item] = 0;
                        context.Identities.Add(new Identity()
                        {
                            Id = item, Key = identities[item]
                        });
                    }
                    else
                    {
                        Identity id = context.Identities
                                      .First(t => t.Id == item);
                        id.Key++;
                        identities[item] = id.Key;
                    }
                }
                context.SaveChanges();
            }
        }
コード例 #2
0
 public void WriteToDatabase(Levels context)
 {
     lock (writeSynchronization)
     {
         foreach (var item in identities.Keys)
         {
             Identity id = context.Identities.FirstOrDefault(t => t.Id == item);
             id.Key = identities[item];
         }
         context.SaveChanges();
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: serkeft49/project-0706
        public static void BatchTest()
        {
            Level1 level1 = new Level1();

            level1.Value  = "test";
            level1.Id     = levelIds[0]++;
            level1.levels = new List <Level2>();
            long ms = 0;

            using (new MetricTracker("Simple save test", t => ms = t))
            {
                for (int i = 0; i < 1296; i++)
                {
                    Level2 curLevel2 = new Level2();
                    level1.levels.Add(curLevel2);
                    curLevel2.Id     = levelIds[1]++;
                    curLevel2.Value  = "test" + i.ToString();
                    curLevel2.levels = new List <Level3>();
                }
                using (Levels context = new Levels())
                {
                    context.Level1.Add(level1);
                    context.SaveChanges();
                }
            }

            using (new MetricTracker("Complex save test - preparation ", t => ms = t))
            {
                level1 = GetSample();
            }

            using (Levels context = new Levels())
                using (new MetricTracker("Complex save test - Save", t => ms = t))
                {
                    context.Level1.Add(level1);
                    context.SaveChanges();
                }
        }