linq 多表分组左连接查询查询统计

var query = (from merchantsInfo in base.GetIQueryable(x => x.IsLogicDelete == false && x.FID != fid)
                         join userAccount in UserAccountBll.GetIQueryable(x => x.PrivilegeLevel > 0)
                         on merchantsInfo.UserAccountID equals userAccount.FID
                         join merchantsfrom in MerchantsInfoFormBLL.GetIQueryable(x => !x.IsLogicDelete)
                         on merchantsInfo.FID equals merchantsfrom.MerchantsInfoID into data
                         from merchants in data.DefaultIfEmpty()
                         group new { merchants.MerchantsInfoID } by new
                         {
                             merchantsInfo.FID,
                             merchantsInfo.Name,
                             merchantsInfo.BrandLabel,
                             merchantsInfo.MainPicture,
                             merchantsInfo.MerchantsAmountMax,
                             merchantsInfo.MerchantsAmountMin,
                             merchantsInfo.MerchantsAmountType,
                             merchantsInfo.ProjectName,
                             merchantsInfo.BelongIndustry,
                             merchantsInfo.BelongIndustryChild,
                             merchantsInfo.MerchantsArea,
                             merchantsInfo.MerchantsAreaCity,
                             merchantsInfo.MerchantsAreaCitySubset
                         } into g
                         select new MerchantsModel
                         {
                             FID = g.Key.FID,
                             Name = g.Key.Name,
                             BrandLabel = g.Key.BrandLabel,
                             MainPicture = g.Key.MainPicture,
                             MerchantsAmountMax = g.Key.MerchantsAmountMax,
                             MerchantsAmountMin = g.Key.MerchantsAmountMin,
                             MerchantsAmountType = g.Key.MerchantsAmountType,
                             ProjectName = g.Key.ProjectName,
                             BelongIndustry = g.Key.BelongIndustry,
                             BelongIndustryChild = g.Key.BelongIndustryChild,
                             MerchantsArea = g.Key.MerchantsArea,
                             MerchantsAreaCity = g.Key.MerchantsAreaCity,
                             MerchantsAreaCitySubset = g.Key.MerchantsAreaCitySubset,
                             ApplyNum = g.Count()
                         }).Take(row).ToList();

猜你喜欢

转载自www.cnblogs.com/chenxi001/p/12551134.html