通过LINQ将表格数据协调到对象中
如何将上述结果转换为以下对象列表通过LINQ将表格数据协调到对象中,linq,Linq,如何将上述结果转换为以下对象列表 StudentId Name AddResss 1 A ABC 1 A XYZ 类结果{ int StudentId{get;set;} 列表地址{get;set;} } 基本上需要按studentId分组源数据结构是什么样的?您尝试过什么?源数据结构是什么样子的?您尝试过什么?源数据结构是什么样子的?您尝试过什么?源数据结构是什么样子的?你
StudentId Name AddResss
1 A ABC
1 A XYZ
类结果{
int StudentId{get;set;}
列表地址{get;set;}
}
基本上需要按studentId分组源数据结构是什么样的?您尝试过什么?源数据结构是什么样子的?您尝试过什么?源数据结构是什么样子的?您尝试过什么?源数据结构是什么样子的?你试过什么?你应该解释你的答案。你应该解释你的答案。你应该解释你的答案。你应该解释你的答案。
Class Result {
int StudentId {get;set;}
List<String> Address {get;set;}
}
var results =
from row in table
group row.Address by new { row.StudentId, row.Name } into g
select new Result { StudentId = g.Key.StudentId, Addresses = g.ToList() };
studentList.GroupBy(x => x.StudentId)
.Select(x => new Result
{
StudentId = x.Key,
Address = x.Select(y => y.AddResss).ToList()
});