NH 3.1 is quite old... Can you check with a newer version (3.4 for .NET 3.5, 4.0 for .NET 4)?
Quentin Villevieille
September 11, 2014 at 9:16 AM
Hi,
We're using NH 3.1.0.4000 with Fluent NH. We have a property of type decimal?, that is later mapped to DECIMAL(7, 0). In the NHProfiler, we can see that that the decimal value is always converted to a string with one decimal place (eg. '1234567.0'). The workaround we've found is to convert the c# property to an int, then convert it back to a decimal?, and it worked perfectly fine. Go figure...
I am using NH 3.0 with fluent mapping.
Here is the linq query:
var query = from invoice in db
where invoice.TotalAmount == totalAmount
select invoice;
"invoice.TotalAmount" and "totalAmount" are both defined as decimal.
Here are the input decimal values and corresponding generated sql:
-------------------------------------------- decimal totalAmount = int.MaxValue;
select <blah blah>
from RadiantBilling.dbo.Invoice invoice0_
where invoice0_.TotalAmount = 2147483647 /* @p0 */
>>> CORRECT <<<
-------------------------------------------- decimal totalAmount = decimal.Add(int.MaxValue, 1);
select <blah blah>
from RadiantBilling.dbo.Invoice invoice0_
where invoice0_.TotalAmount = '2147483648' /* @p0 */
>>> WRONG <<<
-------------------------------------------- decimal totalAmount = decimal.Add(int.MaxValue, 1.0M);
select <blah blah>
from RadiantBilling.dbo.Invoice invoice0_
where invoice0_.TotalAmount = 2147483648.0 /* @p0 */
>>> CORRECT <<<
-------------------------------------------- decimal totalAmount = int.MinValue;
select <blah blah>
from RadiantBilling.dbo.Invoice invoice0_
where invoice0_.TotalAmount = -2147483648 /* @p0 */
>>> CORRECT <<<
-------------------------------------------- decimal totalAmount = decimal.Add(int.MinValue, -1);
select <blah blah>
from RadiantBilling.dbo.Invoice invoice0_
where invoice0_.TotalAmount = '-2147483649' /* @p0 */
>>> WRONG <<<
--------------------------------------------