Page 1 of 1

Specified Cast invalid after upgrade

Posted: Sun 04 Nov 2012 11:57
by edstaffin
Hi,
I have a VERY simple query that is failing after I upgraded from 6.80.350.0 to 7.2.114.0.
All I am doing is a simplet select on a primary key:
var qry = from a in db.EXEMPTIONs
where a.EXEMPTION_SEQ == lExemptionSeq
select a;
return qry.FirstOrDefault();

When I execute the return statement, I get the following error:

Code: Select all

"System.InvalidCastException: Specified cast is not valid.\r\n   at
Devart.Data.Linq.Engine.SingleKeyManager`2.a(Object[] A_0)\r\n   at
Devart.Data.Linq.Engine.KeyManager`2.b(Object[] A_0)\r\n   at
Devart.Data.Linq.Engine.ah.a(Expression A_0, Object& A_1)\r\n   at
Devart.Data.Linq.Engine.ah.e(Expression A_0)\r\n   at
Devart.Data.Linq.DataProvider.a(Expression A_0)\r\n   at
Devart.Data.Linq.Engine.DataQuery`1.System.Linq.IQueryProvider.Execute
[S](Expression expression)\r\n   at System.Linq.Queryable.FirstOrDefault
[TSource](IQueryable`1 source)\r\n   at StewDB.EXEMPTION.GetByPrimaryKey
(StewDBDataContext db, Int32 lExemptionSeq) in c:\\Code\\Dev\\Exemption
\\App_Code\\StewDBPartials.cs:line 101\r\n   at
ExemptionManager.cmdSearch_Click(Object sender, EventArgs e) in c:\\Code \\Dev\\Exemption\\ExemptionManager.aspx.cs:line 169"
Now what's really odd about this is that if I do a db.GetCommand(qry) to see what the sql being generated is, I get the following:

db.GetCommand(qry).CommandText
"SELECT t1.EXEMPTION_SEQ, t1.EXEMPTION_DATE, t1.STATUS_SEQ, t1.RISK_SEQ, t1.START_DATE, t1.END_DATE, t1.DATE_APPROVED, t1.DATE_CLOSED, t1.CROP_SEQ, t1.REGION_SEQ, t1.LOCATION_SEQ, t1.REQUESTOR_LDAP, t1.SOP_DOC_NUMBER, t1.SECTIONS_AFFECTED, t1.CHANGE_SOP, t1.REQUEST, t1.REASON, t1.RISK_ASSESSMENT, t1.CONDITIONS, t1.EXEMPTION_NUMBER, t1.HISTORIC_EXEMPTION_NUMBER, t1.IS_REVIEWED\r\nFROM STEWARDSHIP.EXEMPTION t1\r\nWHERE t1.EXEMPTION_SEQ = 123"

Note the embedded \r\n's at the end? Where did those come from? I'm pretty sure that's what is causeing the problem and I'm also sure that my code has not changed from devart versoin 6.8 to 7.2. It's gotta be some change you folks made. Please help.
Thanks ... Ed

Re: Specified Cast invalid after upgrade

Posted: Sun 04 Nov 2012 13:13
by edstaffin
Here is some more info.
If, instead of:
return qry.FirstOrDefault();
I do the following, it works.

Code: Select all

EXEMPTION oResult = null;
foreach (var item in qry)
    oResult = item;
return oResult;
Something's not right.
Thanks ... Ed

Re: Specified Cast invalid after upgrade

Posted: Mon 05 Nov 2012 14:22
by MariiaI
There is a known issue with InvalidCastException when working with Int16 primary keys. We are working on it now and will inform you when it is fixed.
According to your stack trace, the error, which you are getting, refers to it.

Please confirm that the 'EXEMPTION_SEQ' field is of type Int16 in your sample.
If so, as a workaround you could use a variable of the Int16 type in the query:

Code: Select all

Int16 lExemptionSeq = 123;
var qry = from a in db.EXEMPTIONs
where a.EXEMPTION_SEQ == lExemptionSeq
select a;
return qry.FirstOrDefault(); 

Re: Specified Cast invalid after upgrade

Posted: Mon 05 Nov 2012 14:50
by edstaffin
I don't think we are working with int16's at all. The definition of the pk in our db is:

EXEMPTION_SEQ NUMBER(*,0) NOT NULL ENABLE

The definition in the lqml (the default after the table was dropped on the lqml), is as follows:
Property
Type = System.Decimal
Server Data Type = NUMBER NOT NULL
Auto Generated Value = True

No int16 anywhere to be found.

Re: Specified Cast invalid after upgrade

Posted: Mon 05 Nov 2012 15:02
by edstaffin
More info,
I did as you suggested as a test and got the followign error:
What's up with the embedded \r\n's?
Thanks ... Ed

System.InvalidCastException: Specified cast is not valid.\r\n at
Devart.Data.Linq.Engine.SingleKeyManager`2.a(Object[] A_0)\r\n at
Devart.Data.Linq.Engine.KeyManager`2.b(Object[] A_0)\r\n at
Devart.Data.Linq.Engine.ah.a(Expression A_0, Object& A_1)\r\n at
Devart.Data.Linq.Engine.ah.e(Expression A_0)\r\n at
Devart.Data.Linq.DataProvider.a(Expression A_0)\r\n at
Devart.Data.Linq.Engine.DataQuery`1.System.Linq.IQueryProvider.Execute
[S](Expression expression)\r\n at System.Linq.Queryable.FirstOrDefault
[TSource](IQueryable`1 source)\r\n at StewDB.EXEMPTION.GetByPrimaryKey
(StewDBDataContext db, Int32 lExemptionSeq) in c:\\Code\\Dev\\Exemption
\\App_Code\\StewDBPartials.cs:line 102\r\n at
ExemptionManager.cmdSearch_Click(Object sender, EventArgs e) in c:\\Code \\Dev\\Exemption\\ExemptionManager.aspx.cs:line 169

Re: Specified Cast invalid after upgrade

Posted: Tue 06 Nov 2012 14:02
by MariiaI
Thank you for the additional information. We have reproduced this issue with the 'decimal' data type. We will inform you when it is fixed.
As a workaround, try defining the 'lExemptionSeq' parameter as 'decimal' and tell us about the result:

Code: Select all

decimal lExemptionSeq = 123;
As for the new line symbols ("\r\n"), they are added for better formatting of the query SQL and should not be related to the issue (if there were a mistake with new line characters, you would get a server-side error).

Re: Specified Cast invalid after upgrade

Posted: Tue 06 Nov 2012 14:22
by edstaffin
That works, but is not a tasty work-around. I have 25 applications and who knows how many similar calls spread out all over the place.
Any idea of a timeframe for when this will be fixed? I have been waiting for several months to upgrade from 6.8 because every time I try, I run into another problem/bug.
Thanks ... Ed

Re: Specified Cast invalid after upgrade

Posted: Wed 07 Nov 2012 09:43
by MariiaI
We are investigating the issue, but we can't tell any timeframe at the moment. We will definitely inform you when any results are available.
JIC: there is another workaround for you. According to the definition of your pk:

Code: Select all

EXEMPTION_SEQ NUMBER(*,0) NOT NULL ENABLE
Type = System.Decimal
Auto Generated Value = True
may be it's better to map all the autoincrement fields to "int"( e.g., you could do it manually, or change the default mapping in Tools->Entity Developer->Options->Server Options->Oracle and re-create the model).

Re: Specified Cast invalid after upgrade

Posted: Wed 21 Nov 2012 13:13
by edstaffin
Any news?
Thanks ... Ed

Re: Specified Cast invalid after upgrade

Posted: Fri 23 Nov 2012 17:27
by StanislavK
We have fixed this issue. The fix will be available in the nearest build, which we plan to release next week.

Re: Specified Cast invalid after upgrade

Posted: Mon 26 Nov 2012 13:31
by edstaffin
Cool! I can't wait to get my hands on it!
Thanks ... Ed

Re: Specified Cast invalid after upgrade

Posted: Fri 30 Nov 2012 07:45
by MariiaI
New version of dotConnect for Oracle 7.3 is released!
It can be downloaded from http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=1&t=25388