c# - nHibernate 按年和月分组计数

标签 c# nhibernate linq-to-nhibernate nhibernate-criteria

我正在尝试获取一组文章/博客的所有年份和月份的列表。

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(date) 让它工作,但是它没有在 SQLlite 中运行。如果可能,我需要它与数据库无关。

最佳答案

如果有人偶然发现这个问题,设法解决这个问题。问题是顺序。取出这个解决了错误:

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()
                     });

关于c# - nHibernate 按年和月分组计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21754086/

相关文章:

c# - 如何在linq中选择最大的字符串到nhibernate

nhibernate - 奇怪的 linq 到 nhibernate 问题,来自 'System.Int32' 的无效转换

c# - 形成对象并循环遍历 C# 中的对象?

c# - 当 Enumerable 在 Linq 中有超过 X 个元素时提前返回

nhibernate - ASP.NET MVC 2 RC 模型与 NHibernate 和下拉列表绑定(bind)

nhibernate - 如何在 NServicebus 消息处理程序中注入(inject)多个存储库?

.net - NHibernate Linq 无法调用返回 IQueryable<T> 的常规方法

c# - 如何使用c#读取xls和xlsx文件

c# - 使用 MessageBox 对函数进行单元测试

c# - NHibernate 中具有不同类型答案的问题