Comprehensive Writing of Linq and comprehensive Writing of linq

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.