I have three Tables in SQL with following fileds
1) Order : [OrderID (pk)], [OrderSize], [Thickness], [OD]
2) PipeAllocation : [PipeNo(PK)], [OrderID (fk)], [Length], [Status]
3) Process: [ProcessID (pk)], [PipeNo(fk)], [Date], [MPP]
for adding record in process table I want set value for MPP on criteria of Thickness so I write following code but I got error of "Object reference not set to an instance of an object.". I dont have any null value in thickness field.
my code is
- [HttpPost]
- public ActionResult CreateP3(Process process)
- {
- var tr = process.StageID + process.PIPENO + process.Status;
- var checkme = (from x in db.Processes
- where x.StageID + x.PIPENO + x.Status == tr && x.Status == "OK"
- select x).ToList();
- if (checkme.Count > 0)
- {
- ModelState.AddModelError("PIPENO", "You are trying Duplicate Pipe Entry");
- }
- if (ModelState.IsValid)
- {
-
- if (process.PipeAl.Order.THK > 1)
- {
- process.MPP = 10;
- }
-
- process.CuttingSpeed = (process.ActualMeter*1000)/process.CuttingTime;
- db.Processes.Add(process);
- db.SaveChanges();
- return RedirectToAction("IndexP3");
- }
-
- var EmpAtnList = db.Attens.ToList();
- IEnumerable<SelectListItem> AttnList = from s in EmpAtnList.OrderByDescending(s => s.ATTNDATE)
- select new SelectListItem
- {
- Value = s.ATTNSYSID.ToString(),
- Text = s.ATTNDATE + "--" + s.Emp.EmpName
- };
-
- ViewBag.ATTNSYSID = new SelectList(AttnList, "Value", "Text");
-
-
- ViewBag.StageID = new SelectList(db.OMStages, "StageID", "StageName");
- ViewBag.NextStageID = new SelectList(db.OMStages.OrderBy(x => x.StageValue), "StageID", "StageName");
- ViewBag.PIPENO = new SelectList(db.PipeAls, "PIPENO", "PIPENO");
- ViewBag.Status = new SelectList(db.ValueAddLists.Where(x => x.RefName == "PipeStatus"), "RefValue", "Description", process.Status);
- return View(process);
- }