HQL 中的 avg 聚合函数导致 NHibernate 出现问题,我的查询出了什么问题?

发布于 2024-09-15 17:11:51 字数 697 浏览 1 评论 0原文

HQL 查询遇到问题。如果我从中删除 avg(..) ,它将返回所有空权重,因此问题出在 avg 函数上。 Nhibernate 文档中似乎很清楚,我可以像这样对选择项执行聚合函数。我的问题与 query.ToList 不喜欢返回一件事的列表有关吗?我刚刚收到“无法执行查询[SQL:SQL 不可用]”消息。

 public List<T> HQLQuery<T>(string HQL) //in UnitOfWork
    {
        var query = session.CreateQuery(HQL);
        return query.List<T>().ToList<T>();


    }

   public static float estimateTruckEmptyWeight(int vehicleID)
    {
        UnitOfWork uow = new UnitOfWork();
        List<float> results = uow.HQLQuery<float>("select avg(ev.EmptyWeight) from FieldSystemCore.Domain.EmptyVehicle ev where ev.Vehicle.ID = '" + vehicleID + "'");
        return results[0];

    }

Having trouble with an HQL query. If I remove the avg(..) from it it will return all of the empty weights, so the trouble is with the avg function. It seems clear in the Nhibernate docs that I can perform an aggregate function on the select item like this. Is my problem something to do with query.ToList not liking to return a list of one thing? I just get the "Could not execute query[SQL:SQL not available] message.

 public List<T> HQLQuery<T>(string HQL) //in UnitOfWork
    {
        var query = session.CreateQuery(HQL);
        return query.List<T>().ToList<T>();


    }

   public static float estimateTruckEmptyWeight(int vehicleID)
    {
        UnitOfWork uow = new UnitOfWork();
        List<float> results = uow.HQLQuery<float>("select avg(ev.EmptyWeight) from FieldSystemCore.Domain.EmptyVehicle ev where ev.Vehicle.ID = '" + vehicleID + "'");
        return results[0];

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌︼了一个春 2024-09-22 17:11:51

问题原来是因为 avg 在 Nhibernate 中返回 double,而不是 float。

我希望这个例外能让我知道情况确实如此。

The trouble turned out to be because avg returns double in Nhibernate, not float.

I wish the exception gave me a clue that this was the case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文