HQL 中的 avg 聚合函数导致 NHibernate 出现问题,我的查询出了什么问题?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题原来是因为 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.