我需要从数据库中获取线性图的数据,其中数据流从当前日期n天/周/月/年按这些时间跨度分组。使用外部列表分组linq查询没有间隙
DB中的记录具有与它们关联的DateTime。
给定日期范围列表(开始一天到一天结束或一周开始到一周结束)如何使用linq获得连续流?
在正好没有该日期范围内的记录的情况下,流中没有空白是很重要的。它应该只返回一个零。
这是我试过的,但它不返回任何值。
Dim ranges = Enumerable.Range(0, itemCount).Select(Function(x) DateTime.Now.AddDays(-x).Date).ToList()
Dim stream = Await DB.LogEntries.
OfType(Of LogEntryContentView).
GroupBy(Function(x) DbFunctions.TruncateTime(x.DateStamp)).
Where(Function(x) ranges.Any(Function(y) y < x.Key AndAlso DbFunctions.AddDays(y, 1) > x.Key)).
OrderBy(Function(x) x.Key).
Select(Function(x) x.Count()).
ToListAsync()
(用C#或VB.NET的答案都很好,我知道这两个)