Decimal data type with precision and scale

Topics: General
Oct 7, 2011 at 2:33 AM

Hi,

I have a field 'Price' on my record that is decimal, and I want to store it with a data type of decimal(19,2) but it seems that if I supply the precision it completely ignores everything, and creates the column as numeric(19,0). The following code is from my Migrations.cs:

SchemaBuilder.CreateTable(
	typeof (PriceRecord).Name,
	table => table
		.Column<int>("Id", c => c.PrimaryKey().Identity())
		.Column<int>("ProductPartRecord_Id", c => c.NotNull())
		.Column<int>("InstitutionTypeRecord_Id", c => c.NotNull())
		.Column<decimal>("Price", c => c.NotNull().WithPrecision(19).WithScale(2))
	);

It doesn't make a difference whether I use CreateTable or AlterTable, the result is the same: if I use .WithPrecision, no matter what value I provide it ignores everything and uses (19,0). If I don't call .WithPrecision then the type is (19,5) so I know the database can do it. If I leave off .WithPrecision and just call .WithScale it has no effect. Also calling .WithLength has no effect.

If I use the non-generic .Column("Price", DbType.Decimal, c => c.NotNull().WithPrecision(19).WithScale(2)) the result is the same too -- completely ignores the precision and scale, sets it to (19,0).

I know I could use the default for this instance but I have another field elsewhere that I need to have a scale of 9, so that won't suffice.

I am using Orchard 1.2.41.0 and SQL Compact 4.0.

What am I doing wrong?

Coordinator
Oct 7, 2011 at 2:39 AM

Please file a bug in the issue tracker.

Oct 7, 2011 at 3:18 AM

OK thanks, will do. Is there a work-around? Other than storing it as a string...

Or any way to profile the SQL that it's executing?

Coordinator
Oct 7, 2011 at 3:34 AM

I can't think of a good workaround. You can profile with nhProf.