• C#在一个实体类上新加字段并把另外一个实体类的字段值赋给它


    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); 

  • 相关阅读:
    给div添加disabled属性
    11个让你吃惊的 Linux 终端命令
    在 Linux 平台中调试 C/C++ 内存泄漏方法(转)
    在压缩话单中过滤指定IP的一个小脚本
    过滤IP地址的正则表达式
    【转】网络编程知识
    linux下软链接与硬链接及其区别
    函数式编程入门教程(转)
    suricate学习笔记1--初步认识(转)
    lsof命令详解(转)
  • 原文地址:https://www.cnblogs.com/Depingblogs/p/13150834.html
Copyright © 2020-2023  润新知