public ActionResult Edit([Bind(Include = "CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
        public void ExplicitlyLoading()
        {
            using (var db = new NorthwindDB())
            {
                db.Configuration.LazyLoadingEnabled = false;

                foreach (var p in db.Products)
                {
                    db.Entry(p).Reference(t => t.Category).Load();
                    Console.WriteLine(p.Name + " | " + p.Category.Name);
                }
            }
        }
예제 #3
0
 public ActionResult Edit([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", order.CustomerID);
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", order.EmployeeID);
     ViewBag.ShipVia    = new SelectList(db.Shippers, "ShipperID", "CompanyName", order.ShipVia);
     return(View(order));
 }