Exemplo n.º 1
0
        public void WriteAndReadBack()
        {
            var sw = new Stopwatch();
            sw.Start();
            using (var context = new TestContext("Server=.;Initial Catalog=TestDb;Integrated security=True;"))
            {
                Console.WriteLine("Init " + sw.Elapsed);
                sw.Restart();

                var guid = Guid.NewGuid();
                var newEntity = new ClassD
                {
                    EntityId = guid,
                    Name = "Lorem ipsum",
                    NumberOfSomething = 5
                };
                context.TestTable.Add(newEntity);
                Console.WriteLine("Add " + sw.Elapsed);
                sw.Restart();
                context.SaveChanges();
                Console.WriteLine("Persist " + sw.Elapsed);
                sw.Restart();

                var storedEntity = context.TestTable.SingleOrDefault(e => e.EntityId == guid);
                Console.WriteLine("Select " + sw.Elapsed);

                Assert.IsInstanceOfType(storedEntity, typeof(ClassD));

                var classD = (ClassD) storedEntity;
                Assert.AreEqual(classD.Name, newEntity.Name);
                Assert.AreEqual(classD.NumberOfSomething, newEntity.NumberOfSomething);
                Assert.AreNotEqual(classD.Id, 0);
            }
        }
Exemplo n.º 2
0
 public void InsertNotInTransactionSpeed()
 {
     using (var context = new TestContext("Server=.;Initial Catalog=TestDb;Integrated security=True;"))
     {
         var sum = new Stopwatch();
         sum.Start();
         var sw = new Stopwatch();
         sw.Start();
         for (var i = 0; i < 100; i++)
         {
             var guid = Guid.NewGuid();
             var newEntity = new ClassD
             {
                 EntityId = guid,
                 Name = "Lorem ipsum",
                 NumberOfSomething = 5
             };
             context.TestTable.Add(newEntity);
             Console.WriteLine("Add " + sw.Elapsed);
             sw.Restart();
             context.SaveChanges();
             Console.WriteLine("Persist " + sw.Elapsed);
             sw.Restart();
         }
         Console.WriteLine("-----");
         Console.WriteLine(sum.Elapsed);
     }
 }