2011-07-13 23 views
1

DataSetのためにLinqで左結合を使用すると、エラー "値はnullではありません。パラメータ名の行"になります。Linqの左結合と他の結合の変数の使用

以下は、データとlinqクエリです。

  • DataRowCollection - アイテム(列 - ITEM_ID、SKU、数量)
  • DataRowCollection - キャンペーン(カラム - ITEM_ID、Promotion_Id)
  • DataRowCollection - 成分(カラム - COMPONENT_ID、Promotion_id)
  • DataRowCollection - amount(Columns - Component_id、Amount_Text、currency)

 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、数量割引の詳細:私は次のように取得する必要があり

    すべてのアイテムに割引があったときに左外部結合を残しましたが、いずれのアイテムにも割引がない場合は、そのアイテムをスキップして、左外部結合を使用しなければなりませんでした。

    ご協力いただきまして誠にありがとうございます。明確化が必要な場合はお知らせください。

    ありがとうございます。

  • 答えて

    0

    みんなありがとう。私はこの作業を以下の2つの異なるlinqクエリに分割しました。

    最初のクエリは、2番目のクエリは、クエリを簡素化し、resulsに

     var q = 
          from Item in items 
          join promotion in promoData 
           on Item.Field<int>("Item_id") equals promotion.Item_id into promo 
           from promoJoin in promo.DefaultIfEmpty() 
          select new 
          { 
           SKU = Item.Field<string>("SKU"), 
           Quantity = Item.Field<string>("Quantity"), 
           DiscountAmount = promoJoin != null ? promoJoin.DiscountAmount : "0", 
           DiscountCurrency = promoJoin != null ? promoJoin.DiscountCurrency : "" 
          }; 
    

    このアプローチの作品を取得するためにプロモーションするvarを使用していますVAR

     var promoData = 
           from promotion in promotions 
           join component in components 
            on promotion.Field<int>("Promotion_Id") equals component.Field<int?>("Promotion_Id") 
           join amount in amounts 
            on component.Field<int>("Component_id") equals amount.Field<int?>("Component_id") 
           where component.Field<string>("Type") == "Principal" 
           select new 
           { 
            Item_id = promotion.Field<int?>("Item_id"), 
            Promotion_id = promotion.Field<int>("Promotion_Id"), 
            DiscountAmount = amount == null ? "" : amount.Field<string>("Amount_Text"), 
            DiscountCurrency = amount == null ? "" : amount.Field<string>("currency") 
           }; 
    

    でプロモーションデータを取得します完全に私はすべてのアイテムを得るかどうかは、プロモーションを持っているかどうか。私はまだ同じことが1つのクエリで可能かどうかを考えています:) 誰かが他のよりよい方法を思いつくなら、答えとしてマークしてください。

    0

    あなたはnullのディスク容量のプロパティにアクセスしようとしていると思います。おそらく、あなたの選択の新しいあなたがintoを使用して名前に参加し、その上にDefaultIfEmptyを使っ与える...

    select new 
    { 
        SKU = Item.Field<string>("SKU"), 
        Quantity = Item.Field<string>("Quantity"), 
        DiscountAmount = discamounts == null ? "" : discamounts.Field<string>("Amount_Text"), 
        DiscountCurrency = discamounts == null ? "" : discamounts.Field<string>("currency") 
    }; 
    
    +0

    これは試しましたが、同じエラー "値はnullにはできません。パラメータ名:行" –

    0

    を次のようになります。このような何か(文の最後joinfrom表現を見て)あなたの助けを

    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") into DiscamountJoin 
        from discamount in DiscamountJoin.DefaultIfEmpty() 
        where disccomponent.Field<string>("Type") == "Principal" 
        select new 
        { 
         SKU = Item.Field<string>("SKU"), 
         Quantity = Item.Field<string>("Quantity"), 
         DiscountAmount = discamount.Field<string>("Amount_Text"), 
         DiscountCurrency = discamount.Field<string>("currency") 
        }; 
    
    +0

    入力していただきありがとうございますが、同じエラーで失敗します。私は2 linqクエリでこれを分割し、それが動作します。解決策を投稿します。私がそれをより良くするのを助けることができるかどうか確認してください。 –

    関連する問題