Exemplo n.º 1
0
        private void bindingNavigatorAddNewItem1_Click(object sender, EventArgs e)
        {
            Category category   = (Category)categoryDataGridView.SelectedRows[0].DataBoundItem;
            Product  newProduct = new Product {
                CategoryID = category.CategoryID
            };

            using (var db2 = new ProdContext())
            {
                db2.Products.Add(newProduct);
                db2.SaveChanges();
            }
            db.Products.Attach(newProduct);
            productBindingSource.ResetBindings(false);
        }
Exemplo n.º 2
0
 private void onLoad(object sender, EventArgs e)
 {
     db = new ProdContext();
     db.Categories.Load();
     this.categoryBindingSource.DataSource = db.Categories.Local.ToBindingList();
 }