0

SQL コマンドをlinq
に変換したいのですが、次のメッセージが表示されます。

< Nullable object must have a value >

私のSQLクエリは次のとおりです。

 Select sum(PosList.Cantity) AS cant, sum(PosList.Value) as mysum,PosList.price,PosList.Name
 from list Inner join PosList On list.ID = PosList.FactID 
 WHERE     (list.FirID = 1) AND (PosList.Date BETWEEN '2011-02-22' AND '2012-02-22') 
 GROUP BY PosList.Name, PosList.Price ORDER BY Value DESC

私のリンクは次のとおりです。

    var w = (from item in list join itemPos in PosList   on item.ID equals itemPos.FactID      
  where item.FirID == this.firId && item.Date >= date_start && item.Date <= date_stop   
  group itemPos by itemPos.Name into hh   
  let mysum = hh.Sum(s => s.Value)    
  let cant = hh.Sum(n => n.Cantity)   
  let price = hh.Average(i => i.Price)                                  
  orderby mysum descending  
  select new Agent("", 0, 0, "", hh.Key, "", 0, (double)price, (double)cant, (double)mysum, 0, "", "", "", "", ""));

次のlinqを試しましたが、うまくいきませんでした:

 var w = (from item in list
 join itemPos in PosList  on item.ID equals itemPos.FactID   
 where item.FirID == this.firId && item.Date >= date_start && item.Date <= date_stop   
 group itemPos by itemPos.Name into hh   
 let mysum = hh.Sum(s => s.Value)                    
orderby mysum descending  
 select new Agent("", 0, 0, "", hh.Key, "", 0, (double)hh.Average(i =>i.Price), (double)hh.Sum(n =>n.Cantity), (double)mysum, 0, "", "", "", "", ""));   

正常に動作する唯一のlinqは次のとおりです。

   var w = (from item in list
    join itemPos in PosList
   on item.ID equals itemPos.FactID   
    where item.FirID == this.firId && item.Date >= date_start && item.Date <= date_stop   
    group itemPos by itemPos.Name into hh   
   let mysum = hh.Sum(s => s.Value)                    
   orderby mysum descending  
  select new Agent("", 0, 0, "", hh.Key, "", 0, 0, 0, (double)mysum, 0, "", "", "", "",""));   

しかし、私はそれらの2つの値(価格とカンティティ)も必要です..
ありがとう!

4

1 に答える 1