We're updating the issue view to help you get more done. 

Decimal value with more than 5 decimal places gets truncated when doing a conditional select with linq

Description

My table has two decimal values with precision 15 and scale 9.

1 2 3 4 5 6 7 8 9 10 public partial class TestEntityMap : ClassMap<TestEntity> { public TestEntityMap() { Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.UsePreviousRate).Not.Nullable(); Map(x => x.Rate).Precision(15).Scale(9).Not.Nullable(); Map(x => x.PreviousRate).Precision(15).Scale(9).Not.Nullable(); } }

In my query i want to select which value to select based on a boolean (UsePreviousRate).

1 2 var queryResult = (from test in _session.Query<TestEntity>() select new RateDto { Rate = test.UsePreviousRate ? test.PreviousRate : test.Rate }).ToList();

If PreviousRate is 12345.123456789 i expect the property Rate in RateDto to be the same but the value is rounded to 5 decimals (12345.12346)

Generated SQL looks like

1 select cast(case when testentity0_.UsePreviousRate=1 then testentity0_.PreviousRate else testentity0_.Rate end as DECIMAL(19,5)) as col_0_0_ from [TestEntity] testentity0_

The same query with queryover and conditional projection returns expected value

1 2 3 4 5 6 7 8 9 var query = _session.QueryOver<TestEntity>(() => testEntity) .Select( Projections.Alias(Projections.Conditional(Restrictions.Eq(Projections.Property(() => testEntity.UsePreviousRate), true), Projections.Property(() => testEntity.PreviousRate), Projections.Property(() => testEntity.Rate)), "Rate") .WithAlias(() => rateDto.Rate)); var queryResult = query.TransformUsing(Transformers.AliasToBean<RateDto>()).List<RateDto>(); Assert.AreEqual(12345.123456789M, queryResult[0].Rate);

Generated sql

1 exec sp_executesql N'SELECT (case when this_.UsePreviousRate = @p0 then this_.PreviousRate else this_.Rate end) as y0_ FROM [TestEntity] this_',N'@p0 bit',@p0=1

Environment

MSSQL

Status

Assignee

Alexander Zaytsev

Reporter

Erik jansson

Components

Fix versions

Affects versions

3.3.4.GA

Priority

Major