我有一个场景,我得到一个包含以下值的数据表:
UserId DeptId deptname DependentName
1 45 test test1
1 45 test test2
1 45 test test3
2 46 y firstName
2 46 y firstName1
2 46 y firstName2
我需要一个LINQ查询,我需要获得一个以下格式:
user id = 1
deptid = 45
deptname = test
DependentName = {test1,tes2,test3}
user id = 2
deptid = 46
deptname = y
DependentName = {firstName,firstName1,firstName2}
答案 0 :(得分:0)
什么问题?
var result = ctx.Entity.GroupBy(u => new {
u.UserId,
u.DeptId,
u.DeptName
}).ToList().Select(grouped => new {
GroupKey = grouped.Key,
DeptNames => string.Join(",", grouped.Select(gr => gr.DependentName))
});
答案 1 :(得分:0)
基于MSDN:
melist.GroupBy(e = > new { e.UserId, e.DeptId, e.Deptname }, e);
这应该是这样的:
@pytest.fixture(params=['a'])
def ascii(request):
return ord(request.param)
def test_ascii(ascii):
assert ascii == 97
这个问题已在这里得到解答: C# Linq Group By on multiple columns