mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#18155: Fixing scale for Decimal parameters
Work Item: 18155 --HG-- branch : 1.x
This commit is contained in:
@@ -224,5 +224,22 @@ namespace Orchard.Tests.DataMigration {
|
||||
.AlterColumn("Data", column => column.WithLength(2048)));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PrecisionAndScaleAreApplied() {
|
||||
|
||||
_schemaBuilder
|
||||
.CreateTable("Product", table => table
|
||||
.Column("Price", DbType.Decimal, column => column.WithPrecision(6).WithScale(9))
|
||||
);
|
||||
|
||||
_schemaBuilder
|
||||
.ExecuteSql(String.Format("INSERT INTO TEST_Product (Price) VALUES ({0})", "123456.123456789"));
|
||||
|
||||
var command = _session.Connection.CreateCommand();
|
||||
command.CommandText = "SELECT MAX(Price) FROM TEST_Product";
|
||||
Assert.That(command.ExecuteScalar(), Is.EqualTo(123456.123456789m));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,6 +278,17 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
}
|
||||
|
||||
private string GetTypeName(DbType dbType, int? length, byte precision, byte scale) {
|
||||
|
||||
// NHibernate has a bug in MsSqlCeDialect, as it's declaring the decimal type as this:
|
||||
// NUMERIC(19, $1), where $1 is the Length parameter, and it's wrong. It should be
|
||||
// NUMERIC(19, $s) in order to use the Scale parameter, as it's done for SQL Server dialects
|
||||
// https://nhibernate.jira.com/browse/NH-2979
|
||||
if (_dialect is NHibernate.Dialect.MsSqlCeDialect
|
||||
&& dbType == DbType.Decimal
|
||||
&& scale != 0) {
|
||||
return _dialect.GetTypeName(new SqlType(dbType), scale, precision, scale);
|
||||
}
|
||||
|
||||
return precision > 0
|
||||
? _dialect.GetTypeName(new SqlType(dbType, precision, scale))
|
||||
: length.HasValue
|
||||
|
||||
Reference in New Issue
Block a user