Linq 综合写法

复制代码
 

var queryCount = (from pv in db.Province
join pc in (from cc in
         ((from v in db.ERPStockProductTrigger
         join s in db.Storage on v.StorageID equals s.StorageID
         join b in db.BranchSet on s.BranchSetID equals b.Id
         join p in db.Product on v.ProductID equals p.Id
         join c in db.PriceProfile.Where(w => w.Type == 1) on p.Id equals c.ProductID
         where s.RecordStatus == 1 && s.IsDelivery == true && s.IsWholesale == false
                   && b.BranchType == 53 && b.RecordStatus == 1
                   && p.RecordStatus == 1 && p.ProductName.Contains(pager.ProductName) && p.SkuCode.StartsWith(pager.SkuCode)
       select new { p.SkuCode, s.ProvinceCode }).Distinct())
       group cc by cc.ProvinceCode into gc
       select new { ProvinceCode = gc.Key, Pcount = gc.Count() }) on pv.Code equals pc.ProvinceCode into tpc
from ttpc in tpc.DefaultIfEmpty()

join ps in (from cc in (from r in db.SupermarketProducts
             join p in db.Product on r.ProductId equals p.Id
             join c in db.PriceProfile.Where(w => w.Type == 1) on p.Id equals c.ProductID
             where r.Status == 0 && r.IsEnable == 1 && p.ProductName.Contains(pager.ProductName) && p.SkuCode.StartsWith(pager.SkuCode)
             select new { r.SkuCode, ProvinceCode = r.Province })
             group cc by cc.ProvinceCode into gc
            select new { ProvinceCode = gc.Key, Pcount = gc.Count() }) on pv.Code equals ps.ProvinceCode into tps
from ttps in tps.DefaultIfEmpty()

join pt in (from hr in db.SupermarketProductHis1
             join br in (from cc in db.SupermarketProductHis1
                            group cc by cc.Province into gc
                            select new { Province = gc.Key, ReviseTime = gc.Max(cc => cc.ReviseTime) }
                         ) on new { hr.Province, hr.ReviseTime } equals new { br.Province, br.ReviseTime }
             select new { hr.ReviseTime, hr.Reviser, ProvinceCode = hr.Province }) on pv.Code equals pt.ProvinceCode into tpt
from ttpt in tpt.DefaultIfEmpty()

select new { Province = pv.Code, ProvinceName = pv.Name, SkuSum = (ttpc == null ? 0 : ttpc.Pcount), 
SkuSumSetting = (ttps == null ? 0 : ttps.Pcount), ttpt.ReviseTime, ttpt.Reviser } ); queryCount = queryCount.Where(q => q.SkuSum > 0); if (!string.IsNullOrWhiteSpace(pager.ProvinceCode)) { queryCount = queryCount.Where(q => q.Province == pager.ProvinceCode); } data.total = queryCount.Count(); data.data = queryCount.Select(s => new SupermarketProductSum { Province = s.Province, ProvinceName = s.ProvinceName,
SkuSum = s.SkuSum, SkuSumSetting = s.SkuSumSetting, ReviseTime = s.ReviseTime, Reviser = s.Reviser }).OrderBy(s => s.ProvinceName).ToList();
复制代码

 

复制代码
   var bindSkuList=from s in usedSkuList
                                join e in input.SkuLabels on  new
                                {
                                    s.StorageId,
                                    s.LocationId,
                                    s.SkuId
                                }
                                equals new
                                {
                                    e.StorageId,
                                    e.LocationId,
                                    e.SkuId
                                }
                                select s;
复制代码

 

posted @   cclon  阅读(494)  评论(2编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
点击右上角即可分享
微信分享提示