私は、この変換したいjoin
の操作をforeach
、これは場合にのみ働いていたため、Incoming product
さんmaterialId
とdepotId
で試合をoutgoing product
S 'materialId
とdepotId
。ただし、入荷商品と同じ品目およびデポIDの出庫商品がない場合は、入荷商品の在庫ページへの数量のみを表示したいと思います。したがって、を循環させるforeachを実行し、incomingProductTotals
一致する送信合計を取得して、の内部で残りを実行する必要がありforeach
ます。でもできなかった。
var incomingProductTotals = Model.IncomingProduct
.GroupBy(x => new { x.depotId, x.materialId })
.Select(g => new
{
g.Key.materialId,
g.Key.depotId,
total = g.Sum(t => t.amount)
});
// retrieve all outgoing product totals (with materialId, depotId and total)
var outgoingProductTotals = Model.OutgoingProduct
.GroupBy(x => new { x.depotId, x.materialId })
.Select(g => new
{
g.Key.materialId,
g.Key.depotId,
total = g.Sum(t => t.amount)
});
var totals = incomingProductTotals
.Join(
outgoingProductTotals,
incoming => new { incoming.materialId, incoming.depotId },
outgoing => new { outgoing.materialId, outgoing.depotId },
(incoming, outgoing) => new
{
incoming.materialId,
incoming.depotId,
Total = incoming.total - outgoing.total
});
foreach (var item in totals)
{
<tr>
<td> @item.materialId </td>
<td> @item.depotId </td>
<td> @item.Total</td>
</tr>
}
var incomingProductTotals = Model.IncomingProduct
.GroupBy(x => new { x.depotId, x.materialId })
.Select(g => new
{
g.Key.materialId,
g.Key.depotId,
total = g.Sum(t => t.amount)
});
// retrieve all outgoing product totals (with materialId, depotId and total)
var outgoingProductTotals = Model.OutgoingProduct
.GroupBy(x => new { x.depotId, x.materialId })
.Select(g => new
{
g.Key.materialId,
g.Key.depotId,
total = g.Sum(t => t.amount)
});
foreach(var inProduct in incomingProductTotals)
{
var outProduct = outgoingProductTotals.where(p => p.materialId == inProduct.materialId && p.depotId == inProduct.depotId).FirstOrDefault();
if(outProduct != null)
{
<tr>
<td> @inProduct.materialId </td>
<td> @inProduct.depotId </td>
<td> @(inProduct.Total - outProduct.Total)</td>
</tr>
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加