Reputation: 528
I need help. I've some types defined:
Class1(){int ID; double Price;}
Class2(){int ID; Class1 myClass1;}
Class3(){int ID; List<Class2> Class2List;}
Now I have a list List<Class3> class3List
, from which I need to take only the min double
value (the min Price
). Is this possible to do with LINQ to SQL, or do I need to use foreach
loop?
Upvotes: 0
Views: 248
Reputation: 17064
var min = class3List.SelectMany(x => x.Class2List).Min(x => x.myClass1.Price);
Use SelectMany
method to flatten your list of lists List<List<Class2>>
into List<Class2>
, and then return minimum value in a sequence of prices, fetched by simple selector x => x.myClass1.Price
.
Upvotes: 2