具有双连续选择和分组依据的LINQ查询

时间:2015-04-13 17:24:52

标签: c# linq

我有一个EmployeeInfo个对象的列表,我想从CountryDepartment建立一个表并对Employees进行分组。我需要按国家/地区对EmployeeInfo列表进行分组,然后按部门对每个分组列表组进行分组并处理每个列表。

我尝试了很多方法,但没有让它发挥作用。

我试过这样的事情:

public class EmployeeInfoToTableDataSetTypeConverter : ITypeConverter<List<EmployeeInfo>,                                          
                                                        List<TableDataSet>>
{
    public List<TableDataSet> Convert(ResolutionContext context)
    {
        return
            (from EmployeeInfo in ((List<EmployeeInfo>)(context.SourceValue))
             group EmployeeInfo by EmployeeInfo.Country
                 into EmployeeInfos
                 select //Here I would need to "select" EmployeeInfo from EmployeeInfos 
                 group by EmployeeInfo.Department - but it does not work like this
                   new TableDataSet()

1 个答案:

答案 0 :(得分:0)

这是让你入门的东西:

var groupedList = ((List<EmployeeInfo>)(context.SourceValue)).
   GroupBy(x => x.Country).
   ToDictionary(x => x.Key, x => x.
       GroupBy(y => y.Department));