我正在尝试获取一组文章/博客的所有年份和月份的列表。
var query = (from article in _session.Query<Article>()
where article.Parent == articleList && article.PublishOn != null
group article by new {article.PublishOn.Value.Year, article.PublishOn.Value.Month}
into entryGroup
orderby entryGroup.Key.Year descending, entryGroup.Key.Month descending
select new ArchiveModel
{
Year = entryGroup.Key.Year,
Month = entryGroup.Key.Month,
Count = entryGroup.Count()
});
return query.ToList();
以上编译但nHibernate抛出:
System.NotSupportedException {"NewExpression"}
有没有办法可以使用nHibernate中的任何其他查询方法创建此查询?
我确实设法让它使用SQL Projects并使用YEAR(日期),但是这不能在SQLlite中运行。如果可能的话,我需要它与数据库无关。
答案 0 :(得分:4)
如果有人遇到这个问题,请管理以解决这个问题。问题是订单。拿出来解决了这个错误:
var query = (from article in _session.Query<Article>()
where article.Parent == articleList && article.PublishOn != null
group article by new { article.PublishOn.Value.Year, article.PublishOn.Value.Month } into entryGroup
select new ArchiveModel
{
Year = entryGroup.Key.Year,
Month = entryGroup.Key.Month,
Count = entryGroup.Count()
});