0

知道如何将其转换为 linq 吗?

SELECT DISTINCT PartNumber AS [PartNumber That Includes EVERY ItemNumber Listed in @RequiredItemsTable]
  FROM Part.BillsOfMaterialsFlattened AS bom1 
  WHERE NOT EXISTS
       (SELECT *
          FROM @RequiredItemsTable w
         WHERE NOT EXISTS
               (SELECT *
                  FROM Part.BillsOfMaterialsFlattened AS bom2
                 WHERE (bom1.PartNumber = bom2.PartNumber)
                   AND (bom2.ItemNumber = w.ItemNumber)));

我在这个网站上看到了几个例子,试图模仿它们......但到目前为止还没有到达那里。

谢谢!

这是我希望通过 linq 实现的表格示例。前面的 T-SQL 可以解决问题。

Part.BillsOfMaterialsFlattened
PartNumber  ItemNumber
10041047    10034480
10041047    10041090
10041047    10041091
10041048    10034480
10041048    10041091
10041049    10034650
10041049    10041090
10041049    10041091
10041050    10034650
10041050    10041091
10041061    10001331
10041061    10001422

@RequiredItemsTable
ItemNumber
10041090
10041091

想要生成 LINQ 语句IQueryable<String>

PartNumber (Part Numbers that include all Required Item Numbers)
10041047
10041049
4

1 回答 1

0

以下 linq 可以解决问题:

var requiredItems = criteria.BomItemsIncluded.AsQueryable();
var partNumbers = (from b in _db.BillsOfMaterialsFlatteneds
                    group b by b.PartNumber into g
                    where requiredItems.All(r => g.Select(_ => _.ItemNumber).Contains(r))
                    select g.Key).Distinct();
于 2013-02-01T19:06:17.497 回答