使用Linq和Group by将Datatable转换为Object

我尝试将datatable转换为特殊格式的JSON

DataTable中的数据如下

col1 col2 col3 col4 --------------------- AB c D1 AB c D2 AB c D3 

尝试将其转换为对象数组

 class obj { var col1; var col2; var col3; list col4; } 

我尝试使用linq,但有点卡住了。

  var result = from row in dt.AsEnumerable() group row by new { c1 = row["col1"], c2 = row["col2"], c3 = row["col3"] } into section select new { item = section.Key }; 

 var result = from row in dt.AsEnumerable() group row by new { c1 = r.Field("col1"), c2 = r.Field("col2"), c3 = r.Field("col3") } into section select new { col1 = section.Key.c1, col2 = section.Key.c2, col3 = section.Key.c2, col4 = section.Select(r => r.Field("col4")).ToList() };