Hello, Im stuck with a LINQ group by situation trying to solve it without using foreach statement, here is the escenary:
I Have two generic collections List<OrderHeader>
and List<OrderDetail>
, both have a same field "TOTRGVS" that contains total amount from a order, and the number of order is the key named "NDORGV".
Then I want to found "Orders that not have the same TOTRGVS in OrderHeader and OrderDetail". So for regarding this I try the following query:
List<RGVCAFAC_ERRORES> diff = (from d in lstOrderDetail
join c in lstOrderHeader on d.NDORGV equals c.NDORGV
group d by d.NDORGV into g
let difTOTOrderDetail = g.Select(p => p.TOTRGVS).Sum()
let difTOTOrderHeader = g.Key.????
let diffTOT = difTOTOrderHeader - difTOTOrderDetail
where diffTOT != 0
select new _ERRORS
{
NDORGV = g.Key,
IMPORT = diffTOT
}
).ToList();
in difTOTOrderHeader I dont know how to retrieve the TOTRGVS field from OrderHeader, I have trying using Key but cant get any field, just extensions for formatting methods.
Im in a good way or not?
Thanks.