.GroupBy 和 .Take VB.Net
.GroupBy with .Take VB.Net
我有兴趣根据几个不同的标准过滤一些数据。当我从数据库中提取列表时,我目前有两个 .Where
子句,一个 .GroupBy
和一个 .Take
。我的问题是我想从每个组中取出 3 个并将其添加到我的列表中,这最终不应该是一个分组列表。
这是我一直在使用的一些代码:
Dim dateRangeEnd As New Date(Property.Year, 10, 31)
Dim configurableCount = 3
Dim unfilteredList = _repository.GetIEnumerableFromDB(param1, param2) _
.Where(Function(r) ({status1, status2, status3}) _
.Any(Function(x) r.status.HasValue AndAlso x = r.status.Value)) _
.Where(Function(r) r.StartDate.Value.Year = Property.Year AndAlso r.StartDate.Value < dateRangeEnd) _
.GroupBy(Function(r) r.StartDate.Value.Month) _
.Take(configurableCount)
我如何编辑它以便我只将每个月的 configurableCount
添加到我的列表中?
你用 SelectMany
.
压平了一系列序列
.Where(Function(r) ({status1, status2, status3}) _
.Any(Function(x) r.status.HasValue AndAlso x = r.status.Value)) _
.Where(Function(r) r.StartDate.Value.Year = Property.Year AndAlso r.StartDate.Value < dateRangeEnd) _
.GroupBy(Function(r) r.StartDate.Value.Month) _
.SelectMany(Function(g) g.Take(configurableCount))
我有兴趣根据几个不同的标准过滤一些数据。当我从数据库中提取列表时,我目前有两个 .Where
子句,一个 .GroupBy
和一个 .Take
。我的问题是我想从每个组中取出 3 个并将其添加到我的列表中,这最终不应该是一个分组列表。
这是我一直在使用的一些代码:
Dim dateRangeEnd As New Date(Property.Year, 10, 31)
Dim configurableCount = 3
Dim unfilteredList = _repository.GetIEnumerableFromDB(param1, param2) _
.Where(Function(r) ({status1, status2, status3}) _
.Any(Function(x) r.status.HasValue AndAlso x = r.status.Value)) _
.Where(Function(r) r.StartDate.Value.Year = Property.Year AndAlso r.StartDate.Value < dateRangeEnd) _
.GroupBy(Function(r) r.StartDate.Value.Month) _
.Take(configurableCount)
我如何编辑它以便我只将每个月的 configurableCount
添加到我的列表中?
你用 SelectMany
.
.Where(Function(r) ({status1, status2, status3}) _
.Any(Function(x) r.status.HasValue AndAlso x = r.status.Value)) _
.Where(Function(r) r.StartDate.Value.Year = Property.Year AndAlso r.StartDate.Value < dateRangeEnd) _
.GroupBy(Function(r) r.StartDate.Value.Month) _
.SelectMany(Function(g) g.Take(configurableCount))