2013-07-22 81 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