2

私はこの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();
4

3 に答える 3

6

このようなもの:

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

?: 構文は、条件演算子と呼ばれます。

于 2013-06-13T18:38:26.923 に答える
0

別の を追加する代わりにjoin、次のように別のクエリを使用しますlet

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

ただし、LINQ to SQL がこのようなクエリをどの程度うまく処理するかはわかりません (まったく処理する場合)。

于 2013-06-13T19:09:12.160 に答える
-1
var query= from x in context.a 
       where String.IsNullOrEmpty(param1) || (x.p == param1 && x.i == param2)
        select x;
于 2013-06-13T18:39:22.000 に答える