Decimal gets truncated in EntityBase.SetValue

Posts   
 
    
Posts: 5
Joined: 27-Nov-2009
# Posted on: 20-Aug-2010 16:28:09   

Hi,

I'm using LLBLGenPro designer v 3.0 Final (August 5th, 2010) Template group: self servicing Target Framework: LLBLGen Pro Runtime Framework Target Language: C# Target platform: .Net 4.0

I was faced with a problem I could reproduce in a small sample you can find attached.

There is a VS2010 WPF Project and the llblgen designer project.

Before running the project, you have to change the connection string in the TestApp project settings to point it to the mdb file path.

I use an MS Access "mdb" (2003) database with just one table. I have a nullable currency field named "Price", that translates correctly to a nullable decimal in the generated code for the entity (named TestTableEntity).

I can then read the value correctly when accessing the "Price" property of the entity.

However, if I try to set this value with a decimal, the value gets truncated to an int. This is not a WPF binding issue since it happens when you try to set it programmatically too.

If you trace the code, you will see that the value is still OK when it gets to the property setter for "Price" in TestTableEntity. Then that setter calls SetValue (which I can't trace because i don't have the source) and the value gets truncated.

Best regards.

Manuel Ornato - Multimedia Press

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Aug-2010 07:54:24   

Hi MO,

I reproduced the problem with your repro application. Int he past versions Currency always was taken as scale=2 because OleDb returns always 0 for scale when LLBLGen ask for metadata. So in general it should be scale 2. I will investigate this.

In the meantime, if you can chance to decimal type in DB and set the scale to 2 or 3, etc (instead of Auto), that would be great, as that is the recommended approach when working with money.

David Elizondo | LLBLGen Support Team
Posts: 5
Joined: 27-Nov-2009
# Posted on: 21-Aug-2010 14:17:47   

Hi daelmo,

daelmo wrote:

In the meantime, if you can chance to decimal type in DB and set the scale to 2 or 3, etc (instead of Auto), that would be great, as that is the recommended approach when working with money.

I forced the property and db field scale to 2 in the llblgen designer and it solved the problem.

I will then check if I can change the DB field scale in access without impacting other apps and eventually do it so as to avoid any problem when syncing DB and llblgen models in the future.

Thanks for your help.

Manuel

Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 04-Nov-2010 16:12:55   

daelmo wrote:

Hi MO,

I reproduced the problem with your repro application. Int he past versions Currency always was taken as scale=2 because OleDb returns always 0 for scale when LLBLGen ask for metadata. So in general it should be scale 2. I will investigate this.

In the meantime, if you can chance to decimal type in DB and set the scale to 2 or 3, etc (instead of Auto), that would be great, as that is the recommended approach when working with money.

I'm having the same issue, there is any news?

I'm using: *) LLBLGenPro 2.6 Final (09-Odtober-2009) (Library Lib 2.6.10.0930) *) .Net 3.5, VisualStudio 2010 *) Code generation: Adapter/VB.Net 3.5/Standard Templates *) Database: Access2k

I have a table with some currency columns set to have 4 decimal (scale 4). But the LLBGen Pro designer see these columns wit a "scale: 2" precision, and so the SetValue method truncate the values leaving only 2 decimal. In the designer 2.6 I'm unable to manually change the scale/precision.

What can I do?

Thanks, Massimiliano.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 04-Nov-2010 21:22:38   

I'll check for you and get back to you .

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-Nov-2010 13:06:10   

Max wrote:

daelmo wrote:

Hi MO,

I reproduced the problem with your repro application. Int he past versions Currency always was taken as scale=2 because OleDb returns always 0 for scale when LLBLGen ask for metadata. So in general it should be scale 2. I will investigate this.

In the meantime, if you can chance to decimal type in DB and set the scale to 2 or 3, etc (instead of Auto), that would be great, as that is the recommended approach when working with money.

I'm having the same issue, there is any news?

I'm using: *) LLBLGenPro 2.6 Final (09-Odtober-2009) (Library Lib 2.6.10.0930) *) .Net 3.5, VisualStudio 2010 *) Code generation: Adapter/VB.Net 3.5/Standard Templates *) Database: Access2k

I have a table with some currency columns set to have 4 decimal (scale 4). But the LLBGen Pro designer see these columns wit a "scale: 2" precision, and so the SetValue method truncate the values leaving only 2 decimal. In the designer 2.6 I'm unable to manually change the scale/precision.

What can I do?

Thanks, Massimiliano.

Like David said above, if you use Currency, the scale is not reported by access, so we set it to 2. If you use numeric instead, the scale IS reported. If you want it to be 4, please compile the msaccess driver from sourcecode, and change the line 296 in AccessSchemaRetriever from 2 to 4.

Frans Bouma | Lead developer LLBLGen Pro
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 05-Nov-2010 15:23:18   

Otis wrote:

Like David said above, if you use Currency, the scale is not reported by access, so we set it to 2. If you use numeric instead, the scale IS reported. If you want it to be 4, please compile the msaccess driver from sourcecode, and change the line 296 in AccessSchemaRetriever from 2 to 4.

Ok, I've changed the datatype in the DB: now I use Double instead of Currency for the column that hold a percentage value.

Thanks, Max