I want to make a classification so to speak of a list that I have, I'm trying to do it with linq. well this is what I want ..
Result. This the information with which I count.
Proveedor: Videmont
Cap. Morgan = $450.12
ET. Negra = $620.32
Proveedor: HEB
Cap. Morgan = $400.50
ET. Negra = $508.79
Proveedor: Alamo
Cap. Morgan = $300.48
ET. Negra = $589.46
I want to take the Cap products. Morgan and ET. Negra, whose price is the lowest, of the suppliers. and the result is this, seeing it so simple.
Alamo: Morgan = $300.48
HEB: ET. Negra = $508.79
This is the code with which you already classify the data.
var prove2 = compra.GroupBy(x => x.Proveedor).Select(g => new
{
Proveedor = g.FirstOrDefault().Proveedor,
Productos = g.Select(y => new {
Producto = y.Producto,
PrecioMenor = y.MenorPrecio
}),
CantidadCotizada = g.FirstOrDefault().CantidadCotizada,
MenosPrecio = g.Select(r => r.MenorPrecio).Min(),
}).ToList();
The result is drawn in this scheme.
Proveedor
|__ Productos
|_Producto1
|_ Producto
|_ MenorPrecio
Videmont
|__ Cap. Morgan
|__ $450.12
|__ ET. Negra
|__ $620.32
I would like to take the products with the lowest price of each bone of Morgan and Et. Negra, with its respective provider. I hope someone guides me. thanks