How to create a correct mapping between Oracle column and C# model property?
See original GitHub issueWe are using linq2db. I have the table Pencil
with the column PencilMin
in Oracle database:
PencilMin NUMBER(6, 5)
And in C# I have the following class:
public class Pencil
{
// ... the other code is omitted for the brebity
[Column(Name = "PencilMin", DataType = LinqToDB.DataType.Decimal,
Precision = 6, Scale = 5, CanBeNull = true)]
public decimal? PencilMin { get; set; }
}
And my C# code to insert data:
long id = await dbContext.InsertWithInt64IdentityAsync(dbPencil);
And it generates the following SQL where the type of column PencilMin
is incorrect:
-- Oracle.Managed Oracle12 (asynchronously)
DECLARE @PencilMin Decimal(2, 0) -- incorrect: should be NUMBER(6,5)
SET @PencilMin = 11
DECLARE @IDENTITY_PARAMETER Decimal
SET @IDENTITY_PARAMETER = NULL
INSERT INTO Foo.Pencil
(
PencilMin
)
VALUES
(
:PencilMin
)
RETURNING
ID INTO :IDENTITY_PARAMETER
And the above code returns error:
ORA-01438: value larger than specified precision allowed for this column
I even tried datatype like this, however the result of generated SQL and Oracle error are the same:
[Column(Name = "PencilMin", DbType = "NUMBER(6,5")]
public decimal? PencilMin { get; set; }
Does anybody know how to create a desired mapping PencilMin NUMBER(10,6)
by Column
attribute placed in C# model class?
Additional information:
-
I run the folowing query
SELECT BANNER_FULL FROM v$version
and it showsOracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.14.0.0.0
-
there is no trigger for
PencilMin
field -
ID column type is:
"ID" NUMBER(17,0)
-
Actually, if I run the following query, then the record will be inserted in the database successfully:
-- Oracle.Managed Oracle12 (asynchronously)
DECLARE @PencilMin Decimal(2, 0)
SET @PencilMin = 1
DECLARE @IDENTITY_PARAMETER Decimal
SET @IDENTITY_PARAMETER = NULL
INSERT INTO Foo.Pencil
(
PencilMin
)
VALUES
(
:PencilMin
)
RETURNING
ID INTO :IDENTITY_PARAMETER
Issue Analytics
- State:
- Created 4 months ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Thanks for update. As there is no issue here, I’m closing it. 11 cannot be stored in this field as it requires at least 2 as decimal positions, where your type has only 6-5=1
Tested with the following model:
With no exceptions: