I have the following code. How to convert this into a LINQ? Any one please help me.
In the below code 'powd' contains the db values and purchaseOrderUpdateRequest contains data submitted by user.
bool hasUpdate;
foreach (var item in purchaseOrderUpdateRequest.Lines)
{
var line = powd.PurchaseOrderLines.Single(p => p.ItemNumber == item.ItemNumber);
decimal quantityToReceive = item.QuantityReceived - line.QuantityReceivedToDate;
if (quantityToReceive > 0)
{
hasUpdate =true;
break;
}
}
Thanks.
So all you're trying to work out is whether any item has an update? That's just:
var hasUpdate = purchaseOrder.UpdateRequest.Lines.Any(item =>
item.QuantityReceived < powd.PuchaseOrderLines
.Single(p => p.ItemNumber == item.ItemNumber)
.QuantityReceivedToDate)
I've changed the comparison to just use a direct < rather than a subtraction and a comparison with 0, but this should be okay.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With