每天的 linq 组

发布于 2024-10-20 02:11:49 字数 394 浏览 1 评论 0原文

我有以下分组语句:

var test = from a in MyDC.Table
  where .....
  group a by a.Date into daygroups
  select new MyModel()
  {
    TheCount = (from c in daygroups
               where c.AppointDate < "the date of the daygroups for this day").Sum( d =>d)
           }

基本上,查询在表中查找特定月份内的约会,并按该月的每一天进行计数。 Daygroups 按天对结果进行分组,以便我可以进行每日计数。如何指定日组中的日期?

谢谢。

I have the following grouping statement:

var test = from a in MyDC.Table
  where .....
  group a by a.Date into daygroups
  select new MyModel()
  {
    TheCount = (from c in daygroups
               where c.AppointDate < "the date of the daygroups for this day").Sum( d =>d)
           }

Basically, the query looks in a table for appointments within a certain month and does counts by day for each day of the month. Daygroups groups the results by days so I can do the daily counts. How do I specify the date within the daygroups?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南巷近海 2024-10-27 02:11:49

尝试

 where c.AppointDate <  daygroups.Key

Try

 where c.AppointDate <  daygroups.Key
撩发小公举 2024-10-27 02:11:49

您的日期位于 daygroups.Key 中

使用 LINQ 进行分组时,您分组所依据的值最终出现在 IGrouping 对象(在您的情况下为 daygroups)的 Key 属性中。

也许是这样的:

var test = from a in MyDC.Table
where .....
group a by a.Date into daygroups
select new MyModel {
   TheCount = daygroups.Where(d => d.AppointDate < daygroups.Key).Count()
}

Your date is in daygroups.Key

When grouping with LINQ, the value you are grouping on ends up in the Key property of the IGrouping object, daygroups in your case.

Something like this, perhaps:

var test = from a in MyDC.Table
where .....
group a by a.Date into daygroups
select new MyModel {
   TheCount = daygroups.Where(d => d.AppointDate < daygroups.Key).Count()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文