我正在使用 .NET Core 6、SQL Server 和 Oracle 資料庫。我創建了 2 個物件型別通用串列。所有串列都包含相同型別的資訊。
Line、MaterialName、MaterialId 和 MaterialCount 資訊,我沒有 id 資訊。我無法加入
var productList = new List<object>(); // **used elements**
var reportList = new List<object>(); // **must be used elements**
我有 4 行和 20 種材料。reportList有40個元素,productList有21個。
我需要計算材料的百分位數。我需要將裝配線中使用的材料與使用的材料按百分比進行比例。下面的示例應該使用 2500 主板,但看起來使用的是 2000。所以 100 * 2000 / 2500 = 80。所以效率是 80%。
例子:
reportList element productList element
{ {
"materialId": 1, "materialId": 1,
"line": "Line1", "line": "Line1",
"materialName": "Mainboard", "materialName": "Mainboard",
"materialCount": 2500 "materialCount": 2000
}, },
最終串列元素必須是:
{
"materialId": 1,
"line": "Line1",
"materialName": "Mainboard",
"materialCount": 80
},
If a product has never been used, it will not be registered in the productlist. The percentage number will automatically be 0.(So materialCount must be 0. materialCount = 0). So final list elements count will be same with reportList.
What doesn't work? They are simple generic lists. After "." symbol, we can't use any information because they are list. I can't type something is equal to something. We need something different...
*from report in reportList
join product in productList
on report.Line equals generalRule.Line*
uj5u.com熱心網友回復:
假設,您正在使用 Linq to 物件,您可以使用moreLinq 庫
它有一個LeftJoin擴展方法。
class Element
{
public int materialId { get; set; }
public string line { get; set; }
public string materialName { get; set; }
public double materialCount { get; set; } // Must be double here for the calculation to work
}
var productList = new List<Element>(); // **used elements**
var reportList = new List<Element>(); // **must be used elements**
var result = reportList
.LeftJoin(
productList,
// Join by materialId, line and materialName
r => new { materialId = r.materialId, line = r.line, materialName = r.materialName },
// No element in productList found, materialCount will be 0
r => new Element {materialId = r.materialId, line = r.line, materialName = r.materialName },
// An element in productList was found => do the calculation
(r, p) => new Element {materialId = r.materialId, line = r.line, materialName = r.materialName, materialCount = 100 * p.materialCount / r.materialCount });
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/440809.html
標籤:c# api linq asp.net-core
上一篇:無法運行docker容器
