protected override IEnumerable <RetailAggregationEntity> SearchData() { var lp = VMGlobal.DistributionQuery.LinqOP; var retailContext = lp.Search <BillRetail>(o => o.OrganizationID == VMGlobal.CurrentUser.OrganizationID); var detailsContext = lp.GetDataContext <BillRetailDetails>(); var productContext = lp.GetDataContext <ViewProduct>(); var vipContext = lp.GetDataContext <VIPCard>(); var brandIDs = VMGlobal.PoweredBrands.Select(o => o.ID); var data = from retail in retailContext from details in detailsContext where retail.ID == details.BillID from product in productContext join vip in vipContext on retail.VIPID equals vip.ID into vips from v in vips.DefaultIfEmpty()//生成Left [outer] join左联接语句,就不会产生重复数据了 where product.ProductID == details.ProductID && brandIDs.Contains(product.BrandID) select new RetailEntityForAggregation { OrganizationID = retail.OrganizationID, ProductID = product.ProductID, BrandID = product.BrandID, StorageID = retail.StorageID, CreateTime = retail.CreateTime.Date, StyleCode = product.StyleCode, Quantity = details.Quantity, DiscountMoney = details.Price * details.Quantity * details.Discount / 100, CutMoney = details.CutMoney, VIPCode = v.Code, ShiftID = retail.ShiftID, GuideID = retail.GuideID, //Year = product.Year, //Quarter = product.Quarter, BYQID = product.BYQID }; data = (IQueryable <RetailEntityForAggregation>)data.Where(FilterDescriptors); var result = ReportDataContext.AggregateBillRetail(data); FloatPriceHelper fpHelper = new FloatPriceHelper(); result.ForEach(o => { o.Price = fpHelper.GetFloatPrice(VMGlobal.CurrentUser.OrganizationID, o.BYQID, o.Price); o.CostMoney = o.DiscountMoney - o.CutMoney; }); return(result); }
protected override IEnumerable <RetailAggregationEntity> SearchData() { var lp = VMGlobal.DistributionQuery.LinqOP; var retailContext = lp.GetDataContext <BillRetail>(); var detailsContext = lp.GetDataContext <BillRetailDetails>(); var productContext = lp.GetDataContext <ViewProduct>(); var oids = OrganizationArray.Select(o => o.ID).ToArray(); //var orgContext = lp.Search<ViewOrganization>(o => oids.Contains(o.ID) && o.Flag); var brandIDs = VMGlobal.PoweredBrands.Select(o => o.ID); var data = from retail in retailContext //from org in orgContext //where retail.OrganizationID == org.ID from details in detailsContext where retail.ID == details.BillID && oids.Contains(retail.OrganizationID) from product in productContext where product.ProductID == details.ProductID && brandIDs.Contains(product.BrandID) select new RetailEntityForAggregation { OrganizationID = retail.OrganizationID, ProductID = product.ProductID, BrandID = product.BrandID, CreateTime = retail.CreateTime.Date, StyleCode = product.StyleCode, Quantity = details.Quantity, //Year = product.Year, //Quarter = product.Quarter, BYQID = product.BYQID, DiscountMoney = details.Price * details.Quantity * details.Discount / 100, //这里的CostMoney和Retail表里的CostMoney不一样,相差下面的CutMoney CutMoney = details.CutMoney, Year = product.Year, Quarter = product.Quarter }; data = (IQueryable <RetailEntityForAggregation>)data.Where(FilterDescriptors); var result = ReportDataContext.AggregateBillRetail(data); FloatPriceHelper fpHelper = new FloatPriceHelper(); result.ForEach(o => { o.Price = fpHelper.GetFloatPrice(VMGlobal.CurrentUser.OrganizationID, o.BYQID, o.Price); o.CostMoney = o.DiscountMoney - o.CutMoney; }); return(result); }