question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create a correct mapping between Oracle column and C# model property?

See original GitHub issue

We 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:

  1. I run the folowing query SELECT BANNER_FULL FROM v$version and it shows Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.14.0.0.0

  2. there is no trigger for PencilMin field

  3. ID column type is: "ID" NUMBER(17,0)

  4. 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:closed
  • Created 4 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, May 30, 2023

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

1reaction
sdanylivcommented, May 29, 2023

Tested with the following model:

sealed class Pencil
{
	[Column] public int Id { get; set; }
	[Column(Name = "PencilMin", DataType = LinqToDB.DataType.Decimal, 
		Precision = 10, Scale = 6, 
		DbType = "NUMBER(10,6)",
		CanBeNull = true)]
	public decimal? PencilMin { get; set; }
}

With no exceptions:

db.Insert(new Pencil() { Id = 1, PencilMin = 11 });
-- Oracle.11.Managed Oracle11
DECLARE @Id Int32
SET     @Id = 1
DECLARE @PencilMin Decimal(2, 0)
SET     @PencilMin = 11

INSERT INTO "Pencil"
(
	"Id",
	"PencilMin"
)
VALUES
(
	:Id,
	:PencilMin
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating PL/SQL Mappings
Uses a SQL statement to return two columns that define the range of each chunk, ... Generate the mapping by right-clicking the mapping...
Read more >
Mapping an Oracle data type to a C# property type
When creating a property to correspond to an Oracle column of type NUMBER(6, 3), what factors should I consider before deciding what data ......
Read more >
Copy data to and from Oracle - Azure Data Factory & ...
To copy data from and to Oracle, set the type property of the dataset to OracleTable . The following properties are supported.
Read more >
R2RML: RDB to RDF Mapping Language
Abstract. This document describes R2RML, a language for expressing customized mappings from relational databases to RDF datasets.
Read more >
Is it possibile to customize the default mappings in Oracle. ...
Consider using a different property as the key, or make sure that the database column type matches the model configuration and enable decimal ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found