Reputation: 7215
I am using ODP.NET with EF in an MVC4 application. When performing the below operation,
_db.Set<User>().FirstOrDefault(x => x.Email == Email || x.DisplayName == DisplayName)
it throws exception
[Specified cast is not valid.] Oracle.DataAccess.Client.OracleDataReader.GetDecimal(Int32 i)
What I don't understand is that my User Object has no Int fields, I made them all decimal to smooth things over with Oracle DB. My user table:
CREATE TABLE USERS (
USER_ID NUMBER(38) NOT NULL,
DISPLAY_NAME VARCHAR2(50 CHAR),
IS_LOCKED_OUT_FL VARCHAR2(1 CHAR),
IS_LOCKED_REASON VARCHAR2(256 CHAR),
IS_DELETED_FL VARCHAR2(1 CHAR),
EMAIL VARCHAR2(254 CHAR),
TITLE VARCHAR2(20 CHAR),
FIRSTNAME VARCHAR2(150 CHAR),
SURNAME VARCHAR2(150 CHAR),
DATECREATED DATE DEFAULT SYSDATE,
SCHEME_ID NUMBER(38),
STATUS VARCHAR2(20 CHAR) DEFAULT 'New',
PHONE VARCHAR2(20 CHAR) DEFAULT '',
PRODUCT_ID NUMBER(38) DEFAULT 0,
CONSTRAINT BCARD_USERS_PK PRIMARY KEY (USER_ID),
CONSTRAINT UK_BCARD_USERS UNIQUE (SCHEME_ID))
TABLESPACE SYSTEM
STORAGE (
INITIAL 64K
NEXT 1M
MAXEXTENTS UNLIMITED
)
I don't even know where to start debugging because the error is caused by ODP.NET and I can't step into the library. I should also mention that this doesn't happen on my 32-bit development machine, but the same code throws the exception on a 64-bit production machine using the same 32-bit library. My project was built the target AnyCPU.
Upvotes: 0
Views: 3935
Reputation: 7425
To be clear, the Int32 parameter of the GetDecimal method is the index of the column - it's throwing an error trying to convert column with index 'i'. It's not trying to convert anything to an int.
That said, my guess would be that your User object has a decimal field that's not nullable (decimal?), yet some of your columns like scheme_id and product_id allow nulls in the database.
Upvotes: 1