Linq to entity:如何分组日期时间的日期部分

时间:2012-02-13 12:06:42

标签: c#-4.0 linq-to-entities

我想简单地查询表 Flights ,包含datetime字段 Arrival ,并按日期对结果进行分组,然后使用linq向实体添加分页。

我们如何按到货日期分组航班?

1 个答案:

答案 0 :(得分:3)

由于你正在寻找简单的东西,试试这个。

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

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