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

本文关键字:集中 单个列 连接 linq 查询 | 更新日期: 2023-09-27 18:07:56

我有以下查询:

    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();

我还有另一个表,它与工作订单表连接,并返回多个值。

我想要做的是,我想要加入表并在我的查询中获得它的单列作为集中列,例如(id1,id2,id3)等。我怎样才能做到这一点呢?

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

怎么样:

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();