Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF + ODP.NET: The specified value is not an instance of type 'Edm.Decimal'

I am using Oracle's managed ODP.NET client with Entity Framework. It's working fine. However I am having different behaviours in different servers. I am pretty sure it has something to do with DLL versions, but I could not find any differences so far.

I have these tables:

create table parent (
   parent_id number primary_key, 
   data varchar2(100)
);
create table child (
   child_id number primary key, 
   parent_id number references parent(parent_id)
);

And these entities:

public class Parent {
    Int32 Id { get; set; }
    string Data { get; set; }
}
public class Child {
    Int32 Id { get; set; }
    Parent Parent { get; set; }
}

This is the code:

Entities e = new Entities(connectionString);
Parent p = new Parent();
parent.Data = "TEST DATA!";
Child c = new Child();
c.Parent = p;
e.Children.AddObject(c);
e.SaveChanges(); // exception here, in one server, not on the other

I have a trigger automatically populating the id on both (parent and child), and I am using Store Generated Pattern = Identity on the entity framework configuration.

My issue is:

On my dev machine, it works perfectly as expected. Both rows are inserted on their respective tables. However, on the Server, I am getting an error saying: The specified value is not an instance of type 'Edm.Decimal'.

More info:

Oracle.ManagedDataAccess (v 4.121.1.0) Entity Framework (v v4.0.30319.1)

On both: dev machine (working) + server (not working).

Ideas?

like image 311
Pablo Santa Cruz Avatar asked Oct 02 '22 13:10

Pablo Santa Cruz


1 Answers

Trying changing the definition of your Id column from Int32 to Decimal. I've had this problem several times and I think that fixed it.

public class Parent {
    Decimal Id { get; set; }
    string Data { get; set; }
}
public class Child {
    Decimal Id { get; set; }
    Parent Parent { get; set; }
}
like image 53
Tom Halladay Avatar answered Oct 06 '22 00:10

Tom Halladay