2013-07-22 79 views
0

我從Web服務調用以下函數,但無法獲取定義的對象。linq union group by undefined

Dim x = (From a In _db.report _ 
    Select ep = a.CurrentReport, CuCy = a.Current_Cycle) _ 
    .Union _ 
    (From b In _db.Counts _ 
     Group b By b.Year, b.Report Into k() _ <--------(this is undefined) 
     Select ep = b.Report, CucY = b.Year).ToList().Take(10) 

這是通過聯合查詢進行分組的正確方法嗎?

我將不勝感激任何幫助。

+0

我不是完全肯定這一點,但我認爲'k'後面的括號不需要:'Group By [...] k選擇[012]''''''' – GolfWolf

+1

它們會自動添加。我刪除了它們,但它將它們添加回來。 –

回答

1

VB中的分組語法與C#稍有不同。 Group By要求您聲明Into Group,而不是混淆新的結構。看看你了以下工作:

Dim x = (From a In _db.report _ 
    Select ep = a.CurrentReport, CuCy = a.Current_Cycle) _ 
    .Union _ 
    (From b In _db.Counts _ 
     Group By b.Year, b.Report Into Group _ <--------(this is undefined) 
     Select ep = Key.Report, Key.Year).ToList().Take(10) 

既然你不會出現在第二個查詢進行聚合,你也許可以只是做一個獨特的,而不是:

From b in _db.Counts 
Select b.Report, B.Year 
Distinct