public void Delete(Categories entity)
 {
     Repository.Delete(entity);
 }
 public void Attach(Categories entity)
 {
     Repository.Attach(entity);
 }
 public void Add(Categories entity)
 {
     Repository.Add(entity);
 }
        /// <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>
        /// 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;
        }
        private void FixupCategories(Categories previousValue)
        {
            if (previousValue != null && previousValue.Products.Contains(this))
            {
                previousValue.Products.Remove(this);
            }

            if (Categories != null)
            {
                if (!Categories.Products.Contains(this))
                {
                    Categories.Products.Add(this);
                }
            }
        }