C#在一个实体类上新加字段并把另外一个实体类的字段值赋给它
//条件写法1 var qq = (from t in db.MaintenanceRecords join b in db.EquipMasters on t.EquipID equals b.EquipID select new { MOrder = t.MOrder , Plant = t.Plant , EquipTypeId = t.EquipTypeId , ServiceType = t.ServiceType , remark = (string.IsNullOrEmpty(b.Remark) ? "" : " (" + b.Remark + ")") }).ToList() .Select(t => new MaintenanceRecord() 要重构对象,不然会报错 { MOrder = t.MOrder , Plant = t.Plant , EquipTypeId = t.EquipTypeId , ServiceType = t.ServiceType , remark = t.remark }); qq = qq.Where(condition.FullExpression.Compile());
query.Data = qq.Where(x => plantlist.Contains(x.Plant) //&& x.Status.ToLower() == "ready" && x.ServiceType == "保养(Planned Maintenance-PM)" && x.MaintenanceMan != null && x.MaintenanceMan.Contains(user.EmpNo.ToString())).OrderByDescending(x => x.MOrder).ToPagedList(query.PageIndex, 10);
return View(query);
//条件写法2
IEnumerable<MaintenanceRecord> qq = db.MaintenanceRecords.OrderBy(x => x.ReportedTime); condition.AndIfValid(t => t.ServiceType == "故障(Breakdown-BD)"); qq = qq.Where(condition.FullExpression.Compile()); //query.Data = qq.Where(x => plantlist.Contains(x.Plant) && (x.Status.ToLower() == "ready" || x.Status.ToLower() == "reject") && x.MaintenanceMan != null && x.MaintenanceMan.Contains(user.EmpNo.ToString())).OrderByDescending(x => x.MOrder).ToPagedList(query.PageIndex, 10); //只能看到维修人包含自己的单
PagedList<MaintenanceRecord> MaintenanceR = qq.Where(x => plantlist.Contains(x.Plant) && (x.Status.ToLower() == "ready" || x.Status.ToLower() == "reject") && x.MaintenanceMan != null && x.MaintenanceMan.Contains(user.EmpNo.ToString())).OrderByDescending(x => x.MOrder).ToPagedList(query.PageIndex, 10); //只能看到维修人包含自己的单 foreach (var item in MaintenanceR) { foreach (var item2 in db.EquipMasters) { if(item2.EquipID==item.EquipID) { item.Remark = (string.IsNullOrEmpty(item2.Remark) ? "" : " (" + item2.Remark + ")"); } } } query.Data = MaintenanceR; ViewData["iPhoneorAndroid"] = bm.getiPhoneorAndroid(); return View(query);
|
请发表评论