我需要在LinQ表达式中按季度分组。下面是使用年份的代码:
temp = rmds.GroupBy(a => new { a.reportinggroup, a.timestep.Year })
.Select(g => ....}).ToList();现在,我想用四分之一表达式替换GroupBy中的GroupBy。这是我的分机:
public static int quarter(this DateTime @this)
{
return (int) Math.Ceiling((double)@this.Month / 3);
} 但是如果我在我的LinQ中替换它:
temp = rmds.GroupBy(a => new { a.reportinggroup, a.timestep.quarter() });我得到以下错误:
错误1无效的匿名类型成员声明器。必须使用成员分配、简单名称或成员访问权限声明匿名类型成员。
为什么?我要用什么按季度分组?
发布于 2014-05-07 09:46:01
错误信息告诉您选项是什么。a.timestep.quarter()部件在编写时无效,因为:
foo = a.timestep.quarter())timestep)a.reportinggroup )所以这就是你需要做的:
temp = rmds.GroupBy(a => new { a.reportinggroup, quarter = a.timestep.quarter() })https://stackoverflow.com/questions/23514241
复制相似问题