zoukankan      html  css  js  c++  java
  • 多表连接查询

    List<R_EquipmentContractInfo> objlist = new List<R_EquipmentContractInfo>();
    
                    //所有的合同
                    var contractList = dc_ModelData.Contract_BaseInfor.Where(p => p.BidSectionRowGuid == bidRowGuid).ToList();
                    if (contractList == null || contractList.Count() == 0)
                    {
                        return objlist;
                    }
    
                    //合同所有的物料                
                    var allMT = from g in contractList
                                join m in dc_ModelData.MaterialType.Where(p => p.MonomerProject == bidRowGuid && p.Count > 0) on g.RowGuid equals m.ContractRowGuid
                                select m;
                    var efiles = (from g in allMT
                                  join h in dc_ModelData.EquipmentEFile_Category.Where(p => p.BidSectionRowGuid == bidRowGuid && p.Title == "族文件") on g.RowGuid equals h.MaterialDetailRowGuid into ecGroup
                                  from h2 in ecGroup
                                  join k in dc_ModelData.EquipmentEFile.Where(p => p.BidSectionRowGuid == bidRowGuid && p.IsMaxVersion == true) on h2.RowGuid equals k.ParentRowGuid into efGroup
                                  select new { mt=g,ec=ecGroup,ef=efGroup}).Distinct();
    
                    int mtCount = allMT.Count();
                    int ecount = efiles.Count();
                    foreach (Contract_BaseInfor ec in contractList)
                    {
                        R_EquipmentContractInfo obj = new R_EquipmentContractInfo();
                        obj.rowGuid = ec.RowGuid;
                        obj.name = ec.Name;
    
                        //总数量
                        List<MaterialType> mmdList = allMT.Where(p=>p.ContractRowGuid == ec.RowGuid).ToList();
                        if (mmdList == null || mmdList.Count == 0)
                        {
                            obj.completeCount = 0;
                            obj.unCompleteCount = 0;
                            objlist.Add(obj);
                            continue;
                        }
    
                        List<MaterialType> pmmdlist = (from g in mmdList
                                                       join h in efiles on g.RowGuid equals h.mt.RowGuid
                                                       select g).Distinct().ToList();
                        if (pmmdlist == null || pmmdlist.Count == 0)
                        {
                            obj.completeCount = 0;
                        }
                        else
                        {
                            obj.completeCount = pmmdlist.Count;
                        }
    
                        obj.unCompleteCount = mmdList.Count - obj.completeCount;
    
                        objlist.Add(obj);
    
                    }
    
    
                    return objlist;
  • 相关阅读:
    AtCoder Beginner Contest 169
    Codeforces Round #646 (Div. 2)
    Educational Codeforces Round 88 (Rated for Div. 2)
    Codeforces Round #645 (Div. 2)
    【uoj】【美团杯2020】平行四边形(原根)
    【uoj】【美团杯2020】半前缀计数(后缀自动机)
    Codeforces Round #644 (Div. 3)
    [COI2009] OTOCI
    [AHOI2005] 航线规划
    [P1390] 公约数的和
  • 原文地址:https://www.cnblogs.com/wangzuofei/p/13151997.html
Copyright © 2011-2022 走看看