Beispiel #1
0
        /// <summary>
        /// The fetch single test.
        /// </summary>
        /// <param name="repeatTime">
        /// The repeat time.
        /// </param>
        /// <returns>
        /// The fetch single test.
        /// </returns>
        public long FetchSingleTest(int repeatTime)
        {
            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            using (var db = new TestPerformaceDBEntities())
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    // use entity sql is more faster
                    List <Categories> cats     = db.Categories.Where("it.CategoryID=10").ToList();
                    List <Customers>  cuses    = db.Customers.Where("it.CustomerID='10'").ToList();
                    List <Products>   products = db.Products.Where("it.ProductID=10").ToList();

                    // use linq to entities

                    // var cats = db.Categories.Where(cat => cat.CategoryID == 10).ToList();
                    // var cuses = db.Customers.Where(cut => cut.CustomerID == "10").ToList();
                    // var products = db.Products.Where(p => p.ProductID == 10).ToList();
                }
            }

            sw.Stop();
            return(sw.ElapsedMilliseconds);
        }
        /// <summary>
        /// The fetch single test.
        /// </summary>
        /// <param name="repeatTime">
        /// The repeat time.
        /// </param>
        /// <returns>
        /// The fetch single test.
        /// </returns>
        public long FetchSingleTest(int repeatTime)
        {
            var sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            using (var db = new TestPerformaceDBEntities())
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    // use entity sql is more faster
                    List<Categories> cats = db.Categories.Where("it.CategoryID=10").ToList();
                    List<Customers> cuses = db.Customers.Where("it.CustomerID='10'").ToList();
                    List<Products> products = db.Products.Where("it.ProductID=10").ToList();

                    // use linq to entities

                    // var cats = db.Categories.Where(cat => cat.CategoryID == 10).ToList();
                    // var cuses = db.Customers.Where(cut => cut.CustomerID == "10").ToList();
                    // var products = db.Products.Where(p => p.ProductID == 10).ToList();
                }
            }

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
Beispiel #3
0
        /// <summary>
        /// Writes the test.
        /// </summary>
        /// <param name="repeatTime">The repeat time.</param>
        /// <returns>The write test.</returns>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        public long WriteTest(int repeatTime)
        {
            var dbcontext = new TestPerformaceDBEntities();

            return(Utility.PerformanceWatch(() =>
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    CustomerCRUD(dbcontext);

                    var cat = new Categories
                    {
                        CategoryName = "Widgets",
                        Description = "Widgets are the ……"
                    };

                    var newProduct = new Products
                    {
                        ProductName = "Blue Widget",
                        UnitPrice = 34.56M,
                        Categories = cat
                    };

                    dbcontext.Products.AddObject(newProduct);
                    dbcontext.SaveChanges();

                    //Update category
                    cat.CategoryName = "testupdated";
                    dbcontext.SaveChanges();

                    //Update product
                    newProduct.UnitPrice = 15.8M;
                    dbcontext.SaveChanges();

                    //Delete Products
                    dbcontext.Products.DeleteObject(newProduct);
                    dbcontext.SaveChanges();

                    dbcontext.Categories.DeleteObject(cat);
                    dbcontext.SaveChanges();
                }
            }));
        }
        /// <summary>
        /// The fetch all test.
        /// </summary>
        /// <param name="repeatTime">
        /// The repeat time.
        /// </param>
        /// <returns>
        /// The fetch all test.
        /// </returns>
        public long FetchAllTest(int repeatTime)
        {
            var sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            using (var db = new TestPerformaceDBEntities())
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    List<Categories> cats = db.Categories.ToList();
                    List<Customers> cuses = db.Customers.ToList();
                    List<Products> products = db.Products.ToList();
                }
            }

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
Beispiel #5
0
        private static void CustomerCRUD(TestPerformaceDBEntities dbcontext)
        {
            var cus = new Customers
            {
                CustomerID  = "test",
                CompanyName = "company name",
                ContactName = "contact name",
                Address     = "address"
            };

            dbcontext.Customers.AddObject(cus);
            dbcontext.SaveChanges();


            cus.CompanyName = "update name";
            dbcontext.SaveChanges();

            dbcontext.Customers.DeleteObject(cus);
            dbcontext.SaveChanges();
        }
Beispiel #6
0
        /// <summary>
        /// The fetch all test.
        /// </summary>
        /// <param name="repeatTime">
        /// The repeat time.
        /// </param>
        /// <returns>
        /// The fetch all test.
        /// </returns>
        public long FetchAllTest(int repeatTime)
        {
            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            using (var db = new TestPerformaceDBEntities())
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    List <Categories> cats     = db.Categories.ToList();
                    List <Customers>  cuses    = db.Customers.ToList();
                    List <Products>   products = db.Products.ToList();
                }
            }

            sw.Stop();
            return(sw.ElapsedMilliseconds);
        }
        public void TestGetDBDataWithOutDI()
        {
            var dbcontext = new TestPerformaceDBEntities();
            var contextAdapter = new ObjectContextAdapter(dbcontext);
            var productRepository = new ProductsRepository(
                new EFRepository<Products>(contextAdapter), new EFUnitOfWork(contextAdapter));

            IEnumerable<Products> resultset = productRepository.Repository.Find(p => p.ProductID == 1);

            Assert.IsNotNull(resultset);
            Assert.IsNotNull(resultset.FirstOrDefault().ProductName);
        }
        /// <summary>
        /// Writes the test.
        /// </summary>
        /// <param name="repeatTime">The repeat time.</param>
        /// <returns>The write test.</returns>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        public long WriteTest(int repeatTime)
        {
            var dbcontext = new TestPerformaceDBEntities();

            return Utility.PerformanceWatch(() =>
                                                {
                                                    for (int i = 0; i < repeatTime; i++)
                                                    {
                                                        CustomerCRUD(dbcontext);

                                                        var cat = new Categories
                                                                      {
                                                                          CategoryName = "Widgets",
                                                                          Description = "Widgets are the ……"
                                                                      };

                                                        var newProduct = new Products
                                                                             {
                                                                                 ProductName = "Blue Widget",
                                                                                 UnitPrice = 34.56M,
                                                                                 Categories = cat

                                                                             };

                                                        dbcontext.Products.AddObject(newProduct);
                                                        dbcontext.SaveChanges();

                                                        //Update category
                                                        cat.CategoryName = "testupdated";
                                                        dbcontext.SaveChanges();

                                                        //Update product
                                                        newProduct.UnitPrice = 15.8M;
                                                        dbcontext.SaveChanges();

                                                        //Delete Products
                                                        dbcontext.Products.DeleteObject(newProduct);
                                                        dbcontext.SaveChanges();

                                                        dbcontext.Categories.DeleteObject(cat);
                                                        dbcontext.SaveChanges();

                                                    }
                                                });
        }
        private static void CustomerCRUD(TestPerformaceDBEntities dbcontext)
        {
            var cus = new Customers
            {
                CustomerID = "test",
                CompanyName = "company name",
                ContactName = "contact name",
                Address = "address"
            };

            dbcontext.Customers.AddObject(cus);
            dbcontext.SaveChanges();

            cus.CompanyName = "update name";
            dbcontext.SaveChanges();

            dbcontext.Customers.DeleteObject(cus);
            dbcontext.SaveChanges();
        }
Beispiel #10
0
        /// <summary>
        /// Writes the test.
        /// </summary>
        /// <param name="repeatTime">
        /// The repeat time.
        /// </param>
        /// <returns>
        /// The write test.
        /// </returns>
        public long WriteTest(int repeatTime)
        {
            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            using (var db = new TestPerformaceDBEntities())
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    var cus = new Customers
                    {
                        CustomerID  = "test",
                        CompanyName = "company name",
                        ContactName = "contact name",
                        Address     = "address"
                    };

                    db.AddObject("Customers", cus);
                    db.SaveChanges();

                    cus.CompanyName = "update name";
                    db.SaveChanges();

                    var cat = new Categories {
                        CategoryName = "Widgets", Description = "Widgets are the ……"
                    };

                    // if we have fk
                    // db.AddToCategories(cat);
                    // db.SaveChanges();
                    var newProduct = new Products {
                        ProductName = "Blue Widget", UnitPrice = 34.56M, Categories = cat
                    };

                    db.AddObject("Products", newProduct);
                    db.SaveChanges();

                    // Update
                    cat.CategoryName = "testupdated";
                    db.SaveChanges();

                    newProduct.UnitPrice = 15.8M;
                    db.SaveChanges();

                    // Delete
                    db.DeleteObject(newProduct);
                    db.SaveChanges();

                    db.DeleteObject(cus);
                    db.SaveChanges();

                    db.DeleteObject(cat);
                    db.SaveChanges();
                }
            }

            sw.Stop();
            return(sw.ElapsedMilliseconds);
        }
        /// <summary>
        /// Writes the test.
        /// </summary>
        /// <param name="repeatTime">
        /// The repeat time.
        /// </param>
        /// <returns>
        /// The write test.
        /// </returns>
        public long WriteTest(int repeatTime)
        {
            var sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            using (var db = new TestPerformaceDBEntities())
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    var cus = new Customers
                        {
                            CustomerID = "test",
                            CompanyName = "company name",
                            ContactName = "contact name",
                            Address = "address"
                        };

                    db.AddObject("Customers", cus);
                    db.SaveChanges();

                    cus.CompanyName = "update name";
                    db.SaveChanges();

                    var cat = new Categories { CategoryName = "Widgets", Description = "Widgets are the ……" };

                    // if we have fk
                    // db.AddToCategories(cat);
                    // db.SaveChanges();
                    var newProduct = new Products { ProductName = "Blue Widget", UnitPrice = 34.56M, Categories = cat };

                    db.AddObject("Products", newProduct);
                    db.SaveChanges();

                    // Update
                    cat.CategoryName = "testupdated";
                    db.SaveChanges();

                    newProduct.UnitPrice = 15.8M;
                    db.SaveChanges();

                    // Delete
                    db.DeleteObject(newProduct);
                    db.SaveChanges();

                    db.DeleteObject(cus);
                    db.SaveChanges();

                    db.DeleteObject(cat);
                    db.SaveChanges();
                }
            }

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }