Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Entity Framework decimal error "Specified cast is not valid" on NUMBER

user4938856Dec 18 2015 — edited Dec 18 2015

Has anyone found a good way to map a NUMBER column to to System.Decimal in .Net and EF and make it work for numbers with lots of dp's (without just setting everything to System.Double

i.e.

public decimal VALUE_ { get; set; } will throw "Specified cast is not valid." on numbers with many decimal places...

        [Column("VALUE_")]

        public double VALUE_Temp { get; set; }

        [NotMapped]

        public decimal VALUE_

        {

            get

            {

                return new decimal(VALUE_Temp);

            }

            set

            {

                VALUE_Temp = (double)value;

            }

        }

works but is a rubbish solution..

System.InvalidCastException was unhandled

  HResult=-2147467262

  Message=Specified cast is not valid.

  Source=Oracle.ManagedDataAccess

  StackTrace:

       at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)

       at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)

and

        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)

        {

            modelBuilder.Entity<myEntity>().Property(o => o.VALUE_).HasPrecision(28, 24);

        }

doesn't help//

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2016
Added on Dec 18 2015
1 comment
2,167 views