选择相关孙实体的列表

时间:2014-03-10 20:02:10

标签: c# linq entity-framework

尝试获取具有以下表结构的IEnumerable WorkOrderHeader:

OrderHeader 1:many OrderDetails
OrderDetail 1:1 WorkOrderHeader

代码:

public IEnumerable<WorkOrderHeader> GetInProcessWorkOrdersForOrderBy(OrderHeader orderHeader)
{
    var orderDetails = orderHeader.OrderDetails;
    var workOrders= orderDetails.Select(od => od.WorkOrderHeaders.Where(woh => woh.StatusId < (int)WorkOrderStatus.Complete));
    return workOrders;
}

这将返回嵌套的IEnumerable<IEnumerable<WorkOrderHeader>>。如何获得内部IEnumerable<WorkOrderHeader>

1 个答案:

答案 0 :(得分:2)

我认为您正在寻找SelectMany

var workOrders= orderDetails.SelectMany(od => ...)