NHibernate LINQ 加入 2 个查询以检索最近 4 个供应商的股票
NHibernate LINQ Join 2 queries to retrieve stocks with 4 recent vendors
我必须检索库存和最近的 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 上将 stockDetail 与 vendorhistoryList 一起加入 1 个或多个库存行,最多 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...)
这是我遇到的一个非常相似的问题,所以只是回答了这个问题,这个问题也可以在这里应用。附上那个问题的link。
我必须检索库存和最近的 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 上将 stockDetail 与 vendorhistoryList 一起加入 1 个或多个库存行,最多 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...)
这是我遇到的一个非常相似的问题,所以只是回答了这个问题,这个问题也可以在这里应用。附上那个问题的link。