我正在尝试构建一个Kenndo条形图。我需要打开门票的数量,并关闭门票。我需要按月分组的结果。这是我的LINQ
Dim openTickets = (From t In queue _
Where _
(t.CreateDate.Year = Convert.ToDateTime(DateTime.Now).Year)
Group t By _
ID = CType(t.CreateDate.Month, Integer), _
Month = CType(t.CreateDate.ToString("MMMM"), String) _
Into g = Group _
Select New With _
{.Month = Month.Substring(0, 3), .Opened = g.Where(Function(t) t.CreateDate.Month = ID).Count(Function(t) t.Id)})
Dim closedTickets = (From t In queue _
Where _
(t.CloseDate.Year = Convert.ToDateTime(DateTime.Now).Year)
Group t By _
ID = CType(t.CloseDate.Month, Integer), _
Month = CType(t.CloseDate.ToString("MMMM"), String) _
Into g = Group _
Select New With _
{.Month = Month.Substring(0, 3), .Closed = g.Where(Function(t) t.CloseDate.Month = ID).Count(Function(t) t.Id)})
Dim ticketCount = openTickets.Union(closedTickets)
当我尝试这个时,我得到“WhereSelectEnumerableIterator”。如果我更改第二个查询,使名称为“.Opened”,而不是“.Closed”,则可以正常工作,但后来我不知道“已关闭”的计数。
最终我试图得到一个数组的输出来提供图表......类似于:
[{"Month":"Apr","Opened":138,"Closed":150}
INSTEAD OF
[{"Month":"Apr","Opened":138,"Closed":0},{"Month":"Apr","Opened":0,"Closed":150}
答案 0 :(得分:3)
您需要使用Join
语句合并两者并保持值不同。像这样:
Dim tickets = From open In openTickets _
Join closed In closedTickets _
On open.Month Equals closed.Month _
Select New With _
{.Month = open.Month, .Opened = open.Opened, .Closed = closed.Closed}