Is NHibernate Profiler lying to me?
I am using Fluent NHibernate as my ORM and NH Profiler throws this sql query to me when it is executed
INSERT INTO [Location]
(Name,
Lat,
Lon)
VALUES ('my address' /* @p0 */,
-58.37538459999996 /* @p1 */,
-34.5969468 /* @p2 */);
which is absolutely believable. This is the design of my location table:
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](255) NULL,
[Lat] [decimal](23, 20) NULL,
[Lon] [decimal](23, 20) NULL,
But when I see the inserted data in sqlserver management studio I can see that it is inserted
-58.37538000000000000000 instead of -58.37538459999996000000 and
-34.59694000000000000000 instead of -34.59694680000000000000.
When I run this insert query manually, it inserts the values correctly (14 decimal places for Lat Column), but if nhibernate does it, it only inserts 5 decimal places.
Any ideas ???
source to share
The problem is related to standard precision
and scale
. NHibernate's view is by default decimal
equal decimal (28,5)
, so the final INSERT statement contains only 5 decimal places. XML mapping
<property name="Lat" precision="23" scale="20" />
<property name="Lon" precision="23" scale="20" />
free:
...
.Precision(23)
.Scale(20)
Now the INSERT statement will be decimal (23,20)
.
source to share