Comprehensive Writing of Linq and comprehensive Writing of 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 ();