Specified Cast invalid after upgrade

Specified Cast invalid after upgrade

Postby edstaffin » Sun 04 Nov 2012 11:57

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
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby edstaffin » Sun 04 Nov 2012 13:13

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
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby MariiaI » Mon 05 Nov 2012 14:22

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();
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Specified Cast invalid after upgrade

Postby edstaffin » Mon 05 Nov 2012 14:50

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.
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby edstaffin » Mon 05 Nov 2012 15:02

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
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby MariiaI » Tue 06 Nov 2012 14:02

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).
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Specified Cast invalid after upgrade

Postby edstaffin » Tue 06 Nov 2012 14:22

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
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby MariiaI » Wed 07 Nov 2012 09:43

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).
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Specified Cast invalid after upgrade

Postby edstaffin » Wed 21 Nov 2012 13:13

Any news?
Thanks ... Ed
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby StanislavK » Fri 23 Nov 2012 17:27

We have fixed this issue. The fix will be available in the nearest build, which we plan to release next week.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Re: Specified Cast invalid after upgrade

Postby edstaffin » Mon 26 Nov 2012 13:31

Cool! I can't wait to get my hands on it!
Thanks ... Ed
edstaffin
 
Posts: 43
Joined: Mon 13 Oct 2008 13:23

Re: Specified Cast invalid after upgrade

Postby MariiaI » Fri 30 Nov 2012 07:45

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
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for Oracle