var query = from t in a group t by t.UserID into g select new { UserID = g.Key, OrgID= string.Join(",", g.Select(tt => tt.OrgID).ToArray()), OrgName = string.Join(",", g.Select(tt => tt.OrgName).ToArray()) };
------解决方案--------------------
var query= from x in db.TableA
group x by x.UserID into g
select new
{
ID=g.First().ID,
UserID=g.Key,
OrgID=String.Join(",",g.Select(y=>y.OrgID.Tostring()).ToArray()),
OrgName=String.Join(",",g.Select(y=>y.OrgName).ToArray())
};
------解决方案--------------------
var query= from x in db.TableA.ToList()
group x by x.UserID into g
select new
{
ID=g.First().ID,
UserID=g.Key, UserName = (from u in db.TableB
where UserID ==g.Key
select u.UserName).FirstOrDefault() //假设你的用户表叫TableB , 用户名字段交UserName,你根据你实际的表名和字段修改