0

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?

4

1 回答 1

2
var min = class3List.SelectMany(x => x.Class2List).Min(x => x.myClass1.Price);

使用SelectMany方法将列表列表展平List<List<Class2>>List<Class2>,然后返回由简单选择器获取的价格序列中的最小值x => x.myClass1.Price

于 2013-09-10T08:47:07.750 回答