我正在使用NHibernate 3 Alpha 2,而我正在尝试每月发布一些帖子
这是我提出的代码
List<PostMonthFrequency> monthFrequencies = _postRepository
.FindAll()
//.ToList() //<- if included works. however not desired
.OrderByDescending(x => x.PublishedOn)
.GroupBy(x => new {x.PublishedOn.Year, x.PublishedOn.Month})
.Select(post => new PostMonthFrequency { Month = new DateTime(post.Key.Year, post.Key.Month, 01), Freqency = post.Count() }).ToList();
请不要FindAll将返回Session.Query()
我还试图删除选择
我得到的错误是:
NewExpression
多数民众赞成......我有其他表达方式可以与选择合作,所以我认为不是那样,更多与Groupby有关
提前致谢
PS我的临时修复
List<PostMonthFrequency> monthFrequencies = _postRepository
.FindAll()
.Select(x => x.PublishedOn)
.ToList()
.GroupBy(x => new { x.Year, x.Month })
.Select(post => new PostMonthFrequency { Month = new DateTime(post.Key.Year, post.Key.Month, 01), Frequency = post.Count() })
.ToList();