linq 常用语句

  自己练习的
switch (productDataAnalysisQuery.DataType) { case 1: var data = (from hp in GPEcontext.hbl_product join hcim in from hci in GPEcontext.hbl_change_info where hci.LotNum == 0 && hci.ChangeData < 0 && hci.CreatedTime >= beginDate && hci.CreatedTime <= endDate group hci by new { hci.ProductId } into G select new { ProductId = G.Key.ProductId, Amount = G.Sum(item => Math.Abs(item.ChangeData.Value)) } on hp.id equals hcim.ProductId orderby hcim.Amount descending select new ProductDataAnalysisodel { ProductName = hp.ProductName, ProductCode = hp.ProductCode, Amount = hcim.Amount }).Take(20); pageModel.Models = data.FindBy(item => true, productDataAnalysisQuery.PageNo, productDataAnalysisQuery.PageSize, out total, item => item.Amount, false); break; case 2: var data2 = (from hp in GPEcontext.hbl_product join hcim in from hci in GPEcontext.hbl_change_info where hci.LotNum == 0 && hci.ChangeData < 0 && hci.CreatedTime >= beginDate && hci.CreatedTime <= endDate group hci by new { hci.ProductId } into G select new { ProductId = G.Key.ProductId, Amount = G.Sum(item => Math.Abs(item.ChangeData.Value)) } on hp.id equals hcim.ProductId orderby hcim.Amount select new ProductDataAnalysisodel { ProductName = hp.ProductName, ProductCode = hp.ProductCode, Amount = hcim.Amount }).Take(20); pageModel.Models = data2.FindBy(item => true, productDataAnalysisQuery.PageNo, productDataAnalysisQuery.PageSize, out total, item => item.Amount, false); break; case 3: var data3 = (from hp in GPEcontext.hbl_product join hcim in from hci in GPEcontext.hbl_change_info where hci.LotNum == 0 && hci.ChangeData < 0 && hci.CreatedTime >= beginDate && hci.CreatedTime <= endDate group hci by new { hci.ProductId } into G select new { ProductId = G.Key.ProductId, Amount = G.Count() } on hp.id equals hcim.ProductId orderby hcim.Amount descending select new ProductDataAnalysisodel { ProductName = hp.ProductName, ProductCode = hp.ProductCode, Amount = hcim.Amount }).Take(20); pageModel.Models = data3.FindBy(item => true, productDataAnalysisQuery.PageNo, productDataAnalysisQuery.PageSize, out total, item => item.Amount, false); break; case 4: var data4 = (from hp in GPEcontext.hbl_product join hcim in from hci in GPEcontext.hbl_change_info where hci.LotNum == 0 && hci.ChangeData < 0 && hci.CreatedTime >= beginDate && hci.CreatedTime <= endDate group hci by new { hci.ProductId } into G select new { ProductId = G.Key.ProductId, Amount = G.Count() } on hp.id equals hcim.ProductId orderby hcim.Amount select new ProductDataAnalysisodel { ProductName = hp.ProductName, ProductCode = hp.ProductCode, Amount = hcim.Amount }).Take(20); pageModel.Models = data4.FindBy(item => true, productDataAnalysisQuery.PageNo, productDataAnalysisQuery.PageSize, out total, item => item.Amount, false); break; case 5: var data5 = (from hp in GPEcontext.hbl_product join hs in from hps2 in GPEcontext.hbl_product_stock join p in from hps in GPEcontext.hbl_product_stock group hps by new { hps.ProductID } into G select new { ProductId = G.Key.ProductID, CreatedTime = G.Max(p => p.CreatedTime) } on new { A = hps2.ProductID, B = hps2.CreatedTime } equals new { A = p.ProductId, B = p.CreatedTime } select new { ProductId = hps2.ProductID, Amount = hps2.Stock } on hp.id equals hs.ProductId orderby hs.Amount descending select new ProductDataAnalysisodel { ProductName = hp.ProductName, ProductCode = hp.ProductCode, Amount = hs.Amount.Value }).Take(20); pageModel.Models = data5.FindBy(item => true, productDataAnalysisQuery.PageNo, productDataAnalysisQuery.PageSize, out total, item => item.Amount, false); break; case 6: var data6 = (from hp in GPEcontext.hbl_product join hs in from hps2 in GPEcontext.hbl_product_stock join p in from hps in GPEcontext.hbl_product_stock group hps by new { hps.ProductID } into G select new { ProductId = G.Key.ProductID, CreatedTime = G.Max(p => p.CreatedTime) } on new { A = hps2.ProductID, B = hps2.CreatedTime } equals new { A = p.ProductId, B = p.CreatedTime } select new { ProductId = hps2.ProductID, Amount = hps2.Stock } on hp.id equals hs.ProductId orderby hs.Amount select new ProductDataAnalysisodel { ProductName = hp.ProductName, ProductCode = hp.ProductCode, Amount = hs.Amount.Value }).Take(20); pageModel.Models = data6.FindBy(item => true, productDataAnalysisQuery.PageNo, productDataAnalysisQuery.PageSize, out total, item => item.Amount, false); break; }

 

你可能感兴趣的:(linq 常用语句)