我有一个 sql 查询,想把它转换成 linq
SELECT CAST([Date] AS DATE),
COUNT([ID]) AS 'Amount of Systems'
FROM [DemoDB].[dbo].[Servers]
WHERE [ServerID] IN ('ServerX') AND [Type] = 'Complete'
GROUP BY CAST([Date] AS DATE)
ORDER BY CAST([Date] AS DATE)
这将返回结果如下
我试过的
//fromDP and toDP are the names of the Datepicker's
var query = (this.db.Servers
.Where(x => x.Date >= fromDP.SelectedDate.Value &&
x.Date <= toDP.SelectedDate.Value));
var query_Success = query.Count(p => p.Type == "Complete"
&& (p.ServerID == "ServerX"));
并且我将结果作为整体计数(例如,如果我选择从 April 1st 到 April 15th ,结果是所有“完成”的总和),但我需要在这个选定范围内的每一天计数。结果我将绑定到柱形图。如何进行 ?