【发布时间】:2011-10-04 09:07:45
【问题描述】:
当我在 Linq 中为 DataSet 使用左联接时,我遇到了错误“值不能为空。参数名称行”。
以下是数据和 linq 查询。
- DataRowCollection - 项目(列 - Item_id、SKU、数量)
- DataRowCollection - 促销(列 - Item_id、Promotion_Id)
- DataRowCollection - 组件(列 - Component_id、Promotion_id)
- DataRowCollection - 金额(列 - Component_id、Amount_Text、货币)
var q =
from Item in items
join promotion in promotions
on Item.Field<int>("Item_id") equals promotion.Field<int?>("Item_id") into promo
from promotion in promo.DefaultIfEmpty()
join disccomponent in components
on promotion.Field<int>("Promotion_Id") equals disccomponent.Field<int?>("Promotion_Id")
join discamounts in amounts
on disccomponent.Field<int>("Component_id") equals discamounts.Field<int?>("Component_id")
where disccomponent.Field<string>("Type") == "Principal"
select new
{
SKU = Item.Field<string>("SKU"),
Quantity = Item.Field<string>("Quantity"),
DiscountAmount = discamounts.Field<string>("Amount_Text"),
DiscountCurrency = discamounts.Field<string>("currency")
};
我需要得到以下信息:
- 有折扣的商品的 SKU、数量和折扣详情
- SKU,无折扣商品的数量
当所有项目都有折扣时,代码在没有左外连接的情况下工作,但如果任何项目没有任何折扣,它会跳过该项目,因此我必须使用左外连接。
非常感谢任何帮助。如果需要任何澄清,请告诉我。
提前致谢。
【问题讨论】: