- 3,715,657 Users
- 2,242,821 Discussions
- 7,845,481 Comments
Forum Stats
Discussions
Categories
- 17 Data
- 362.2K Big Data Appliance
- 7 Data Science
- 1.6K Databases
- 467 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 22 Multilingual Engine
- 487 MySQL Community Space
- 3 NoSQL Database
- 7.6K Oracle Database Express Edition (XE)
- 2.8K ORDS, SODA & JSON in the Database
- 416 SQLcl
- 42 SQL Developer Data Modeler
- 184.8K SQL & PL/SQL
- 21K SQL Developer
- 1.9K Development
- 3 Developer Projects
- 32 Programming Languages
- 135.1K Development Tools
- 8 DevOps
- 3K QA/Testing
- 247 Java
- 5 Java Learning Subscription
- 10 Database Connectivity
- 66 Java Community Process
- 1 Java 25
- 9 Java APIs
- 141.1K Java Development Tools
- 6 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 135 Java 8 Questions
- 86.2K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 10 Java SE
- 13.8K Java Security
- 3 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 125 LiveLabs
- 30 Workshops
- 9 Software
- 3 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 3 Deutsche Oracle Community
- 10 Español
- 1.9K Japanese
- 2 Portuguese
Oracle.EntityFrameworkCore beta3 Specified cast is not valid

Hello!
I'm trying to read entity from table. But catching
System.InvalidCastException: 'Specified cast is not valid.'
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetString(Int32 i)
at lambda_method(Closure , DbDataReader )
at Microsoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferAll()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable`1 results, QueryContext queryContext, IList`1 entityTrackingInfos, IList`1 entityAccessors)+MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Opn.Lib.Dotnet.EntityFramework.Core.TestConsole.MyHostedService..ctor(TestDbContext context) in C:\Sources\UFS.Dotnet.Lib\opn.lib.dotnet.entityframework.core\Opn.Lib.Dotnet.EntityFramework.Core.TestConsole\MyHostedService.cs:line 13
Table script:
CREATE TABLE "ITEMSSTORE" ( "ID" NUMBER(38,0) NOT NULL ENABLE, "BIGNUM38" NUMBER(38,0), "BIGINTCOL" NUMBER(19,0), "INTCOL" NUMBER(10,0), "GUIDCOL" RAW(16), "DATECOL" DATE, "DATETIMEOFFSETCOL" TIMESTAMP (6) WITH TIME ZONE, "DECIMALCOL" NUMBER(28,0), "STRINGCOL" NVARCHAR2(2000), "DATETIMECOL" TIMESTAMP (6), "TIMECOL" INTERVAL DAY (2) TO SECOND (6), CONSTRAINT "ITEMSSTORE_PK" PRIMARY KEY ("ID") ); INSERT INTO itemsstore ( bignum38, bigintcol, intcol, guidcol, datecol, datetimeoffsetcol, decimalcol, stringcol, datetimecol, timecol ) VALUES ( 12345678912345678912345678912345678912, 9223372036854775807, 2147483647, 'fd55e62a0646449f9375a0d86449f77c', '01-01-2001', '01-01-01 12:12 +3:00', 9228162514264337593543950335, N'У попа была собака он её любил, она съела кусок мяса он её убил, закопал её в могилу на могиле написал, у попа была собака он её любил...', '01-01-01 12:12', INTERVAL '11:20' HOUR TO MINUTE );
Entity:
[Table("ITEMSSTORE")] internal class TestItems { [Column("ID")] [Key] public long? Id { get; set; } [Column("BIGNUM38")] [MaxLength(38)] public string GiantCol { get; set; } [Column("BIGINTCOL")] public long? BigIntCol { get; set; } [Column("INTCOL")] public int? IntCol { get; set; } [Column("GUIDCOL")] public Guid? GuidCol { get; set; } // В базе это Raw[16] [Column("DATECOL")] public DateTime? DateCol { get; set; } [Column("DATETIMEOFFSETCOL")] public DateTimeOffset? DateTimeOffsetCol { get; set; } [Column("DECIMALCOL")] public decimal? DecCol { get; set; } [Column("STRINGCOL")] [MaxLength(2000)]
public string StrCol { get; set; } [Column("DATETIMECOL")] public DateTime? DateTimeCol { get; set; } [Column("TIMECOL")] public TimeSpan? TimeCol { get; set; } }
Best Answer
-
ODP.NET EF Core provides a default data type mapping between Oracle DB data types and .NET Core data types. Nonetheless, Oracle and .NET data types do not match each others' min and max possible values. You will have to adjust these mappings based on your application data using Annotations or Fluent API.
The PDF doc contained in the Beta 3 has suggested mappings that you can use based on different size number, text, and binary data.
Answers
-
ODP.NET EF Core provides a default data type mapping between Oracle DB data types and .NET Core data types. Nonetheless, Oracle and .NET data types do not match each others' min and max possible values. You will have to adjust these mappings based on your application data using Annotations or Fluent API.
The PDF doc contained in the Beta 3 has suggested mappings that you can use based on different size number, text, and binary data.
-
thx, I catch error. NUMBER(38) can't be mapped to string. There is any way to get numbers greater then decimal.MAX?
-
Well, you can't force a .NET data type to hold more than its maximum value. You can only use another data type that has a larger maximum or alternative storage method that preserves the data.
You can try manually modifying the mapping after it is generated to a string or another data type that can hold a NUMBER(38).