NHibernate: wrong column type: found float, expected double precision

I have a domain entity class with the property:

public virtual double? Result { get; set; } 

The property is converted using NHibernate 3.2 type display material:

 public class SampleResultMap : ClassMapping<SampleResult> { public SampleResultMap() { Id(c => c.Id, map => map.Generator(Generators.Identity)); Property(c => c.Result, map => { map.NotNullable(false); }); // More properties, etc. } } 

This works fine, and the SQL Server 2008 R2 table is correctly created with the float data type.

However, a call to SchemaValidator.Validate raises this error:

 NHibernate.HibernateException was unhandled Wrong column type in Foo.dbo.SampleResult for column Result. Found: float, Expected DOUBLE PRECISION 

If you look at the SQL invoked by the call to SchemaExport.Create , this is the definition for the table:

 create table SampleResult ( Id INT IDENTITY NOT NULL, DateEnteredUtc DATETIME not null, ElementId INT not null, Unit INT not null, ResultText NVARCHAR(50) null, [Result] DOUBLE PRECISION null, Detected BIT not null, Qualifier NVARCHAR(10) null, SampleId INT not null, Deleted BIT not null, primary key (Id) ) 

From a quick read of NHibernate 3.2 sources, it seems that the validator compares "DOUBLE PRECISION" with "float".

Has anyone else seen this? I suppose this is a mistake, but I did not use the validator before I wanted to find out if I was doing something wrong.

+4
source share
1 answer

I had a similar problem with initialized identifiers in SQLite DB, which was caused by the fact that SQLite only supports auto-increment on whole columns.

NHibernate correctly created the identifier column as an integer, but when he checked it, he thought it should be an int instead of an integer. Since int just maps an integer to SQLite, I just created a new dialect to use an integer instead of int, and now it works fine.

Since DOUBLE PRECISION is the same as FLOAT (53) on SQLServer, it could be the same thing: viewing a float instead of double precision. As a job, you can try changing the dialect to use FLOAT (53) instead:

 using System.Data; using NHibernate.Dialect; public class UpdatedMsSql2008Dialect : MsSql2008Dialect { public UpdatedMsSql2008Dialect() : base() { RegisterColumnType(DbType.Double, "FLOAT(53)"); } } 

The SQLServer dialect source seems to suggest that it should work. It definitely looks like there is a validator error.

+4
source

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


All Articles