Пример #1
0
 public void Remove(Product entity)
 {
     using (DbContext context = new ProductsBrandsDbContext())
     {
         context.Entry(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public void Update(Brand entity)
 {
     using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
     {
         context.Brands.Attach(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #3
0
        public void Update(Product entity)
        {
            using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
            {
                //avoiding duplicate brands
                Brand brand = context.Brands.Find(entity.BrandId);
                entity.Brand = brand;

                context.Products.Attach(entity);
                context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }