将所有子列表连接在一起并抓取第一个子列表

本文关键字:列表 抓取 第一个 在一起 连接 | 更新日期: 2023-09-27 17:55:18

我希望能够提取包含类别中产品的最后一张发票类别->产品->发票

(from p as Product in cat
 where p.InvoiceList.Where(function(o) o.InvoiceDate >= MAX_ONE)
 select p.InvoiceList.Where(function(o) o.InvoiceDate >= MAX_ONE)
).FirstOrDefault()

我似乎无法理解如何完成这项工作。

编辑:一个示例SQL语句,可以实现我的目标。 要是我能翻译就好了...

SELECT    TOP 1 i.InvoiceID, i.InvoiceDate, i.TotalAmount
FROM         Category as c INNER JOIN
                  Product as p ON p.categoryID = c.categoryID INNER JOIN
                  InvoiceProducts as ip ON ip.productID = p.productID INNER JOIN
                  Invoice as i ON ip.InvoiceID = i.InvoiceID 
WHERE     c.categoryID = 3
ORDER BY InvoiceDate DESC

将所有子列表连接在一起并抓取第一个子列表

cat.SelectMany(p => p.InvoiceList).OrderBy(o => o.InvoiceDate).LastOrDefault();
var lastInvoice = (from i in context.Invoices
    .where i.Product.CategoryId == categoryId
    .select i)
        .OrderByDescending(i=>i.IbvoiceDate)
        .FirstOrDefault();