Linq to 实体:如何对日期时间的日期部分进行分组

发布于 2025-01-05 08:52:59 字数 105 浏览 4 评论 0原文

我想简单地查询表航班,包含日期时间字段到达,并按日期对结果进行分组,然后使用 linq to 实体添加分页。

我们如何按抵达日期对航班进行分组?

I would like to simply query table Flights, contains datetime field Arrival, and group results by date, then add paging using linq to entity.

How can we group flights by arrival dates?

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

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

发布评论

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

评论(1

も让我眼熟你 2025-01-12 08:52:59

既然您正在寻找简单的东西,请尝试一下。

int recordsPerPage = 10, currentIndex = 0;
var groupQuery =
    myDC.Flights.
    GroupBy(f => EntityFunctions.TruncateTime(f.Arrival)).
    Skip(recordsPerPage * currentIndex).
    Take(recordsPerPage);

这将为您返回 Flight 对象组,您可以按照您的计划使用它们。

Since you're looking for something simple, try this out.

int recordsPerPage = 10, currentIndex = 0;
var groupQuery =
    myDC.Flights.
    GroupBy(f => EntityFunctions.TruncateTime(f.Arrival)).
    Skip(recordsPerPage * currentIndex).
    Take(recordsPerPage);

This will give you back groups of Flight objects which you can use however you plan.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文