Decimal field truncated using NHibernate 3.2 and FluentnHibernate 1.3

I have a situation where the decimal field is truncated to five decimal places when saving to the database. This happens even if I have mapped them with 10 decimal places precision.

I use NHibernate 3.2.0.4000 and FluentNHibernate 1.3.0.717 in SQL Server 2008.

This is my C# attribute:

public virtual decimal? MyDecimalField {get; set; }

I tried to do an automatic mapping overlay:

mapping.Map( x => x.MyDecimalField).Precision(28).Scale(10);

I also tried to explicitly map the field:

 Map(x => x.MyDecimalField).Precision(28).Scale(10);

When exporting the mode, the table will be created correctly:

create table MyTable (
Id UNIQUEIDENTIFIER not null,
MyDecimalField DECIMAL(28, 10) null,
primary key (Id)
)

Use value 5.1234567890, the following is the parameter fragment in the generated SQL update statement:

@p31 decimal(28,5)
@p31=5.12345

If I use XML mapping, I can work normally:

< p>I removed all the conventions for the decimal field, but there are still problems.

Since the XML-based mapping works, this leads me to believe that it is a problem with Fluent. Anything else I might have missed Suggest?

Thank you,
jump

I will answer myself here Thank you @Firo for providing me with some tips to guide me to the solution.

I have an agreement to set the default length of my string field:

public void Apply(IPropertyInstance instance)
{
instance.Length(350);
}

But my acceptance criteria did not exclude Decimal field. I added excluded decimals in some acceptance criteria:

public void Accept(IAcceptanceCriteria criteria)
{
criteria
.Expect(x => x.Type != typeof(decimal) && x.Type != typeof(decimal?));
}

This corrected my decimal precision .

Interestingly, my default string length of 350 does not appear in the XML mapping file of the decimal field I exported. But it seems that FNH still uses it somehow. This seems to me It is an FNH error.

I have a situation where the decimal field is truncated to five decimal places when saving to the database. Even though I have used precision mapping with 10 decimal places They, this happens too.

I use NHibernate 3.2.0.4000 and FluentNHibernate 1.3.0.717 in SQL Server 2008.

This is my C# attribute:

public virtual decimal? MyDecimalField {get; set; }

I tried to do an automatic mapping override:

mapping.Map(x => x.MyDecimalField).Precision(28).Scale(10); 

I also tried to explicitly map fields:

Map(x => x.MyDecimalField).Precision(28).Scale(10 );

When executing the mode export, the table will be created correctly:

create table MyTable (
Id UNIQUEIDENTIFIER not null,
MyDecimalField DECIMAL(28, 10) null,
primary key (Id)
)

Use the value 5.1234567890, the following is the parameter fragment in the generated SQL update statement:

@p31 decimal(28,5)
@p31=5.12345

If I use XML mapping, I can work normally:

I deleted all the conventions for the decimal field, but there are still problems.

p>

Since the XML-based mapping works, this leads me to believe it is a problem with Fluent. Any suggestions on other things I might have missed?

Thanks,
jump

I will answer my own question here. Thanks @Firo for providing me some guidance My solution skills.

I have a convention to set the default length of my string field:

public void Apply(IPropertyInstance instance)
{
instance.Length(350);
}

But my acceptance criteria did not exclude decimal fields. I added exclusions in some acceptance criteria Decimal:

public void Accept(IAcceptanceCriteria criteria)
{
criteria
.Expect(x => x.Type! = typeof(decimal) && x.Type != typeof(decimal?));
}

This corrected my decimal precision.

Interestingly, My default string length of 350 does not appear in the XML mapping file of the decimal field I exported. But it seems that FNH still uses it somehow. This seems to be an FNH error to me.

Leave a Comment

Your email address will not be published.