将连接集中在linq查询中的单个列中

时间:2016-09-20 10:43:40

标签: c# linq

我有以下查询:

SELECT Id, Salary
FROM Employees
WHERE ManagerId IS NULL

我还有另一个表,它与workorder表连接,并返回多个值。

我想要做的是,我想加入表并在我的查询中将它的一列作为一个集中列,例如(id1,id2,id3)等。我怎样才能实现这一目标?

1 个答案:

答案 0 :(得分:0)

怎么样:

var query = (from wo in _dbContext.WorkOrder
                 join opr in _dbContext.Operation
                 on wo.operationID equals opr.operationID
                 where wo.orderid == selectedorderid
                 select new {wo.orderid, wo.workOrderID, wo.itemID, wo.operationID, opr.operationName, wo.operationCode}).ToList();

var orders = queryGroupBy(i => i.workOrderID)
                .Select(i => new {WorkOrderId = i.workOrderID, ConcatinatedIds = String.Join(", ", i.Select(j => j.operationID))})
                .ToList();