需要linq帮助:尝试向master添加细节



我没有做太多处理头和细节记录的工作。我需要创建一个订单对象并添加IList<lineItems(添加到标头记录内的属性。我试着做一个加入并放弃。我调用两个存储过程,一个用于标头,另一个用于详细信息
我所要做的就是填充我的"IList";在报头有效载荷中。我不断地得到";查询主体必须以select"结束;不知道如何完成。我确信还有更好的方法使用加入,但如果我能让它发挥作用,我会很兴奋。


var orderHeaderRecords = ctx.sparGetOrderConfirmationRecords_WED(runDate).ToList();
var orderDetailRecords = ctx.sparGetOrderConfirmationRecordsDetail_WED(runDate).ToList();
var order = (from o in orderHeaderRecords
//gave up on join
//join od in orderDetailRecords on new { o.RecordType, o.OrderNumber } equals new { od.RecordType, //od.OrderNumber }

select new OrderConfirmation()
{
BillAddr1 = o.BillToAddr1,
BillAddr2 = o.BillToAddr2,
IsOfficeOrder = Convert.ToBoolean(o.IsOfficeOrder),
OrderConfirmationType = EnumHelper.GetValueFromDescription<ConfirmationType>(o.RecordType),
LineItems = new List<LineItem>()
}).ToList();

order.ForEach(or =>

{   or.LineItems.AddRange((from line in orderDetailRecords.Where(x => 
x.RecordType == or.OrderConfirmationType.ToDescription() 
&& x.OrderNumber == or.OrderNumber).Select(od =>
new LineItem(
{
Desc = od.Description,
ExtAmt = od.ExtPrice.Value,
ItemId = od.Item                                                  } 
).Select(rec => rec).ToList()); //.ToList()));
});
```
The last line of code (body must end with a select or group by)  
I just need to get the detail records in the "List" on the master record.  
order.ForEach(or =>                    
{   or.LineItems.AddRange(
orderDetailRecords
.Where(x => x.RecordType == or.OrderConfirmationType.ToDescription() && x.OrderNumber == or.OrderNumber)
.Select(od =>
new LineItem(
{
Desc = od.Description,
ExtAmt = od.ExtPrice.Value,
ItemId = od.Item                                                  } 
)).ToList());
});

最新更新