Exemplo n.º 1
0
        private void Save_Click(object sender, EventArgs e)
        {
            pContext.SaveChanges();
            pContext.Categories.Load();
            this.dataGridView1.Refresh();

            pContext.Products.Load();
            this.dataGridView2.Refresh();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var db = new ProdContext())
            {
                //Console.Write("Write a name of a category: ");
                //string name = Console.ReadLine();
                //AddCategory(name, db);
                //ShowAllCategoriesQuery(db);
                //ShowAllCategoriesMethod(db);

                var entity = db.Products.Find(1);
                db.Entry(entity).Property("UnitsInStock").CurrentValue = 10;
                entity = db.Products.Find(2);
                db.Entry(entity).Property("UnitsInStock").CurrentValue = 2;
                entity = db.Products.Find(3);
                db.Entry(entity).Property("UnitsInStock").CurrentValue = 5;
                db.SaveChanges();

                ShowAllCategoriesAndProducts showAll = new ShowAllCategoriesAndProducts(db);
                showAll.ShowAllCategoriesAndProductsEagerLoading();


                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();

                var categoryForm = new CategoryForm();
                categoryForm.ShowDialog();
            }
        }
Exemplo n.º 3
0
        static void AddCategory(string name, ProdContext context)
        {
            var category = new Category {
                Name = name
            };

            context.Categories.Add(category);
            context.SaveChanges();
        }