public ActionResult Edit([Bind(Include = "intEquipmentID,intGarageRoom,intManufacturerID,intModelID,strManufYear,intSNPrefixID,strSerialNo,intEquipmentTypeID,intSMCSFamilyID,intSizeID,CreateDate,intMetered,LastDate,intLastMetered,intTotalMetered,intlimitDay,intlimitWeek,bitActive,bitPreservation,bitMeter,bitKTG,isDelete,intLocationId,strDescription,floatCostTires,intCostTiresCurrency,floatAverageDivergence,floatFullPrice,intFullPriceCurrency,dateStartUpDate,intServiceLife,intHoweverOddsAcceleration,bitMethodAmortization")] newEquipment newEquipment) { if (ModelState.IsValid) { db.Entry(newEquipment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.intManufacturerID = new SelectList(db.TablesManufacturers, "intManufacturerID", "strManufacturerChecklistId", newEquipment.intManufacturerID); ViewBag.intModelID = new SelectList(db.TablesModels, "intModelID", "strName", newEquipment.intModelID); return(View(newEquipment)); }
//private static MCSEntities db = new MCSEntities(); static void Main(string[] args) { MCSEntities db = new MCSEntities(); db.Database.Log = Console.Write; //явная загрузка TablesModel model = db.TablesModels.Find(1); foreach (var source in db.TablesSNPrefixes.Where(w => w.intModelID == model.intModelID)) { model.TablesSNPrefixes.Add(source); } db.Entry(model).Collection(c => c.TablesSNPrefixes).Load(); return; //Ленивая (отложенная) загрузка foreach (var tablesModel in db.TablesModels.Take(5)) { Console.WriteLine(tablesModel.strName); foreach (var tablesSnPrefix in tablesModel.TablesSNPrefixes) { Console.WriteLine(" -" + tablesSnPrefix.strPrefix); } } return; //Прямая загрузка List <newEquipment> equipments = db.newEquipments.Include(d => d.TablesLocation).Include(d => d.TablesManufacturer).Include(d => d.TablesModel.TablesSNPrefixes).ToList(); Console.WriteLine("-----------------------------------"); foreach (var newEquipment in equipments) { Console.WriteLine(newEquipment.intGarageRoom); foreach (var pref in newEquipment.TablesModel.TablesSNPrefixes) { Console.WriteLine("->" + pref.strPrefix); } } Console.WriteLine("--------------------------------------------"); }
static void Main(string[] args) { db.Database.Log = Console.Write; //Явная загрузка TablesModel model = db.TablesModel.Find(1); db.Entry(model).Collection(c => c.TablesSNPrefix).Load(); return; //Lazy load foreach (var tablesModel in db.TablesModel.Take(5)) { Console.WriteLine(tablesModel.strName); foreach (var tablesSnPrefix in tablesModel.TablesSNPrefix) { Console.WriteLine(" -" + tablesSnPrefix.strPrefix); } } return; //Прямая загрузка List <newEquipment> equipList = db.newEquipment //.Include(d => d.TablesLocation) //.Include(d => d.TablesModel) //.Include(d => d.TablesModel.TablesSNPrefix) .ToList(); Console.WriteLine("------------------------------------------------"); foreach (var newEquipment in equipList) { Console.WriteLine(newEquipment.intGarageRoom); foreach (var pref in newEquipment.TablesModel.TablesSNPrefix) { //Console.WriteLine("->" + pref.strPrefix); } } Console.WriteLine("--------------------------------------------------"); }