linq union group by undefined

时间:2013-07-22 14:24:28

标签: linq linq-to-entities

我从Web服务调用以下函数但无法获取定义的对象。

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)

这是在联合查询中执行分组的正确方法吗?

我将不胜感激。

1 个答案:

答案 0 :(得分: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