No puedo obtener el registro más alto de una lista
Frecuentes
Visto 51 veces
0
I have two lists, ddr.Out and ddr.Dil. The first list I have to group by contract and then order descending by contract and then by amount since there can be several records with the same contract and I want just the one with the highest amount.
Then I have to update each amount in ddr.out with the amount from contracts that exist in ddr.dil.
My prolem is that I can't fit in this statement a way to get just the highest amount from ddr.out.
Any ideas? Rui Martins
ddr.Out.GroupBy(ou => ou.Contract);
ddr.Out.OrderByDescending(ou => ou.Contract).ThenByDescending(ou=> ou.Amount);
ddr.Out.ForEach(ou => ou.Amount += ddr.Dil
.Where(dil => dil.Referred &&
dil.Wad == wad &&
dil.Cycle == cal.ID &&
dil.Contract == ou.Contract)
.Select(dil => dil.Amount)
.FirstOrDefault());
1 Respuestas
0
You can get the largest amount in ddr.Dil
usar IEnumerable
's Funcion max.
Also note that the documentation on Para cada dice:
Modifying the underlying collection in the body of the Action<T> delegate
is not supported and causes undefined behavior.
Rather make a new collection using Select
y reemplazar el ddr.Out
:
newOut =
ddr.Out.GroupBy(ou => ou.Contract)
.OrderByDescending(ou => ou.Contract)
.ThenByDescending(ou=> ou.Amount)
.Select(ou => ou.Amount += ddr.Dil
.Where(dil => dil.Referred &&
dil.Wad == wad &&
dil.Cycle == cal.ID &&
dil.Contract == ou.Contract)
.Max(dil => dil.Amount));
Respondido 28 ago 12, 12:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas linq list group-by sql-order-by record or haz tu propia pregunta.