gpt4 book ai didi

c# - 我如何在 linq 的 select 语句中使用 where 子句。 (即在属性(property)上。)

转载 作者:行者123 更新时间:2023-12-02 05:01:03 25 4
gpt4 key购买 nike

我有这个 linq 查询:

var sku = (from a in con.MagentoStockBalances
join b in con.MFGParts on a.SKU equals b.mfgPartKey
join c in con.DCInventory_Currents on b.mfgPartKey equals c.mfgPartKey
where a.SKU != 0 && c.dcKey ==6
select new
{
Part_Number = b.mfgPartNumber,
Stock = a.stockBalance,
Recomended = a.RecomendedStock,
Cato = c.totalOnHandQuantity
}).ToList();

现在我需要删除 c.dcKey ==6 条件并有这样的东西:

var sku = (from a in con.MagentoStockBalances
join b in con.MFGParts on a.SKU equals b.mfgPartKey
join c in con.DCInventory_Currents on b.mfgPartKey equals c.mfgPartKey
where a.SKU != 0
select new
{
Part_Number = b.mfgPartNumber,
Stock = a.stockBalance,
Recomended = a.RecomendedStock,
Cato = c.totalOnHandQuantity where c.dcKey == 6,
Kerry = c.totalOnHandQuantity where c.dcKey == 7
}).ToList();

最佳答案

像这样:

Cato = c.dcKey == 6 ? c.totalOnHandQuantity : 0,
Kerry = c.dcKey == 7 ? c.totalOnHandQuantity : 0

?: 语法称为条件运算符。

关于c# - 我如何在 linq 的 select 语句中使用 where 子句。 (即在属性(property)上。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com