我必须找回股票和最近的4家供应商。我在一个清单中得到了库存。与另一个列表中的供应商订购。想要获得所有股票与最近4家供应商的合并结果(如果有的话)。我对LINQ不好,这也是NHibernate
这是我的最新作品。寻求如何编写第三个LINQ sql来获得这个。
IEnumerable<StockDetailReportModal> stockDetail = Session.Query<Stock>()
.Where(predicate)
.ToList()
.Select(n => new StockDetailReportModal
{
Id = n.Id,
Number = n.Number,
PaddedNumber = n.PaddedNumber,
Buyer = n.Buyer == null ? string.Empty : n.Buyer.FullName,
SalesTaxCode = n.SalesTaxCode == null ? null : n.SalesTaxCode.Code,
PurchasingUnitOfMeasure = n.PurchasingUnitOfMeasure,
InventoryUnitOfMeasure = n.InventoryUnitOfMeasure,
CatalogueDescription = n.CatalogueDescription,
BrandDescription = n.BrandDescription,
EconomicOrderQuantity = n.EconomicOrderQuantity,
LastYearPurchasePrice = n.LastYearPurchasePrice,
ThisYearIssuePrice = n.ThisYearIssuePrice,
NextYearIssuePrice = n.NextYearIssuePrice,
Description = n.StockCommodityCode == null ? string.Empty : n.StockCommodityCode.Code + "-" + n.StockCommodityCode.Description,
}).OrderBy(o => o.VendorNumber);
var vendorhistoryList = Session.Query<PurchaseOrderLineItem>()
.Where(pOpredicate)
.Where(p => p.Stock.Number != null)
.ToList()
.Select(c => new
{
stockId = c.Id,
LastPurchaseDate = c.PurchaseOrder.OrderDate.ToString("yyyy/MM/dd"),
VendorNumber = c.PurchaseOrder.PurchaseOrderVendor.Vendor.Number,
LastPurchasePrice = c.UnitPrice,
LastTransactionDate =
c.LastTransactionDate != null ? c.LastTransactionDate.Value.ToString("yyyy/MM/dd") : null,
LeadTimeDays = GetDays(c.PurchaseOrder.OrderDate, c.LastTransactionDate),
}).GroupBy(d => d.VendorNumber).Select(gpo => gpo
.OrderByDescending(x => x.LastPurchaseDate)
.Take(4));
当vendorhistoryList对象没有显示任何属性时,我的问题从这里开始。我在这做错了什么?我试图在stock.id上与vendorhistoryList一起加入stockDetail,其中包含一个或多个最近有4个供应商的库存行。请建议我该怎么做?
这是我需要的最后一部分。
var stockdetailResult = from sd in stockDetail
join vh in vendorhistoryList on sd.Id equals vh.Id into sv
from vs in sv.DefaultIfEmpty() ???
.select ( c=> c.fields1....c.fields2...)
答案 0 :(得分:0)
这是我遇到的一个非常类似的问题所以刚刚回答了这个问题,也可以在这里应用。附上该问题的链接。