如何使用Linq将列表集合添加到列表中?

时间:2012-08-07 07:15:57

标签: c# linq entity-framework

我有一个清单

List<List<Employee>> EmployeeListCollection;

并希望

List<Employee> EmployeeList=//all employee in EmployeeListCollection

查询是什么?

2 个答案:

答案 0 :(得分:12)

List<Employee> EmployeeList = EmployeeListCollection.SelectMany(c => c).ToList();

答案 1 :(得分:0)

试试这个:

List<List<Employee>> EmployeeListCollection;
List<Employee> EmployeeList;
foreach(var emplst in EmployeeListCollection)
{
  foreach(var emp in emplst )
 {
     EmployeeList.add(emp);
 }
}