Esempio n. 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _context = new ProductsEntities3();

            // Call the Load method to get the data for the given DbSet
            // from the database.
            // The data is materialized as entities. The entities are managed by
            // the DbContext instance.
            _context.Categories.Load();

            // Bind the categoryBindingSource.DataSource to
            // all the Unchanged, Modified and Added Category objects that
            // are currently tracked by the DbContext.
            // Note that we need to call ToBindingList() on the
            // ObservableCollection<TEntity> returned by
            // the DbSet.Local property to get the BindingList<T>
            // in order to facilitate two-way binding in WinForms.
            this.categoryBindingSource.DataSource =
                _context.Categories.Local.ToBindingList();
        }
Esempio n. 2
0
        private void TestInit()
        {
            using (ProductsEntities3 ctx = new ProductsEntities3())
            {
                Product p = new Product
                {
                    Name = "P10",
                };

                Category c = new Category
                {
                    Name = "C10"
                };

                ctx.Products.Add(p);
                ctx.Categories.Add(c);

                c.Products.Add(p);

                ctx.SaveChanges();
            }

            MessageBox.Show("TestInit Completed");
        }