How to get the total sum () function of NHibernate to return a decimal number?

I cannot get sum () to return a decimal number, and it always returns an int64 truncating the decimal places. I have googled all day, but I can’t find a real job. I have a DB table called ProductPurchase with

QtyPurchased (integer) as well as UnitPurchasePrice Columns (money),

they map to a C # POCO object using NHibernate, where QtyPurchase is an int and UnitPurchasePrice is a decimal property.

I have the following HQL query where I want to get the total purchase amount for a given day:

select the amount (detail.QtyPurchased * detail.UnitPurchasePrice) from Domain.Entities.ProductPurchase AS detail where dateiff ("day", detail.PurchaseDate ,: trading_date) = 0

Now, for whatever reason, query.UniqueResult always returns an Int64 integer, decreasing decimal numbers, while the generated SQL obviously returns the correct decimal number. Can someone shed somelight on how to get this to return decimal numbers?

I noticed that if I use SQL (i.e. CreateSqlQuery), I can return the decimal. Is this a bug with Nhibernate?

Thanks heaps

Stephen Kuo

+3
source share
1 answer

Inverting the order of factors did this for me: (price * qty) instead of (qty * price).

I assume that it should only check the first type of parameter, please fill out the JIRA issue if this workaround worked for you.

+2

Source: https://habr.com/ru/post/1706017/


All Articles