获取sum的值
using (var session = SessionFactory.OpenSession())
{
var q = from p in session.Query<PurchaseDeliveryInfo>().Where(predicate)
select (decimal?)p.Amount;
var sum = q.Sum();
return sum ?? 0;
}
可以通过NHibernate的linq方式获取聚合函数的值。
string hql = "select sum(p.Amount) FROM PurchaseDeliveryInfo p WHERE p.PurchaseId=:PurchaseId AND p.IsConfirm!=:Revocation";
using (var session = SessionFactory.OpenSession())
{
IQuery query = session.CreateQuery(hql);
query.SetInt32("PurchaseId", PurchaseId);
query.SetParameter("Revocation", EnumConfirmReceipt.撤销);
return (decimal?)query.UniqueResult() ?? 0;
}
通过HQL语句的方式获取聚合函数的值。