示例#1
0
        /// <summary>
        /// WriteTest
        /// </summary>
        /// <param name="repeatTime"></param>
        /// <returns></returns>
        public long WriteTest(int repeatTime)
        {
            return(Utility.PerformanceWatch(
                       () =>
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    using (var db = new TestPerformaceDBDB())
                    {
                        //Insert
                        var customer = new Customer
                        {
                            CompanyName = "Newcvompanyname",
                            ContactName = "ccc",
                            Address = "asdcadsdws",
                            ContactTitle = "adsdf",
                            City = "ku2na",
                            Country = "chi2na",
                            Phone = "231",
                            PostalCode = "234",
                            Region = "ASIA",
                            CustomerID = "9011"
                        };

                        var custmId = db.InsertWithIdentity(customer);


                        var cat = new Category {
                            CategoryName = "Widgets234", Description = "Widgets are 43the ……"
                        };

                        var newProduct = new Product {
                            ProductName = "Blue Widget234", UnitPrice = 35.56M, Category = cat
                        };

                        var catgoriesId = db.InsertWithIdentity(cat);
                        var productionId = db.InsertWithIdentity(newProduct);

                        //Update
                        db.Products
                        .Where(p => p.ProductID == 10)
                        .Set(p => p.ProductName, "test prod")
                        .Update();

                        db.Categories
                        .Where(p => p.CategoryID == 10)
                        .Set(p => p.CategoryName, "test cat")
                        .Update();

                        //Delete
                        db.Delete(customer);
                        db.Delete(newProduct);
                        db.Delete(cat);
                    }
                }
            }));
        }
示例#2
0
 /// <summary>
 /// FetchSingleTest
 /// </summary>
 /// <param name="repeatTime"></param>
 /// <returns></returns>
 public long FetchSingleTest(int repeatTime)
 {
     return(Utility.PerformanceWatch(
                () =>
     {
         for (int i = 0; i < repeatTime; i++)
         {
             using (var db = new TestPerformaceDBDB())
             {
                 var categories = db.Categories.Find(10);
                 var customer = db.Products.Find(10);
                 var product = db.Customers.Find("10");
             }
         }
     }));
 }
        /// <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 dbcontext3 = new TestPerformaceDBDB();
            return Utility.PerformanceWatch(
                   () =>
                   {
                       for (int i = 0; i < repeatTime; i++)
                       {

                           CustomerModelCRUD(dbcontext3, i);

                           var category = new Category()
                           {
                               CategoryName = "AirLine",
                               Description = "For Air"
                           };

                          category.CategoryID= dbcontext3.Insert.Into<Category>(c => c.CategoryName, c => c.Description).Values(category.CategoryName,category.Description).Execute();

                          dbcontext3.Update<Category>().Set("CategoryName").EqualTo("testupdate").Where<Category>(x => x.CategoryID == category.CategoryID).Execute();

                           var product = new Product()
                           {
                               ProductName = "testproduct1",
                               UnitPrice = 10,
                               QuantityPerUnit = "tt",
                               SupplierID = 3,
                                CategoryID=category.CategoryID

                           };

                           product.ProductID = dbcontext3.Insert.Into<Product>(p => p.ProductName, p => p.UnitPrice, p => p.QuantityPerUnit, p => p.SupplierID)
                               .Values(product.ProductName, product.UnitPrice, product.QuantityPerUnit, product.SupplierID).Execute();

                           dbcontext3.Update<Product>().Set("ProductName").EqualTo("updateproductname").Where<Product>(p => p.ProductID == product.ProductID).Execute();

                           dbcontext3.Delete<Category>(x => x.CategoryID == category.CategoryID).Execute();

                           dbcontext3.Delete<Product>(x => x.ProductID == product.ProductID).Execute();

                       }
                   });
        }
        /// <summary>
        /// Customers the model CRUD.
        /// </summary>
        /// <param name="dbcontext3">The dbcontext3.</param>
        /// <param name="i">The i.</param>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        private static void CustomerModelCRUD(TestPerformaceDBDB dbcontext3, int i)
        {
            var c1 = new Customer();
            c1.CompanyName = "company";
            c1.CustomerID = "T" + i;

            //insert
            dbcontext3.Insert.Into<Customer>(c => c.CustomerID, c => c.CompanyName).Values(c1.CustomerID, c1.CompanyName).Execute();
            //update
            dbcontext3.Update<Customer>().Set("CompanyName").EqualTo("test").Where<Customer>(x => x.CustomerID == c1.CustomerID).Execute();
            //delete
            dbcontext3.Delete<Customer>(x => x.CustomerID == c1.CustomerID).Execute();
        }