Specified cast is not valid

Specified cast is not valid

Postby dilbert » Fri 14 Sep 2012 15:30

EDIT: This post is Linq specific and should be posted in LinqConnect section. Sry.

I experience problem with Linq query. Tested with both Mysql and Sqlite provider. I'm using version 7.2.77 resp. 4.2.77.

It can be reproduced with following table:

Code: Select all
CREATE TABLE `data_currency` (
  `Id` smallint(6) NOT NULL AUTO_INCREMENT,
  `Currency` varchar(15) NOT NULL,
  PRIMARY KEY (`Id`)
)


Field "Id" is mapped to type "Int16". Then following query throws exception:
Code: Select all
DB.DataCurrencies.Where(c => c.Id == 1).SingleOrDefault();


Code: Select all
Specified cast is not valid
Devart.Data.Linq.Engine.SingleKeyManager`2.a(Object[] A_0)
Devart.Data.Linq.Engine.KeyManager`2.b(Object[] A_0)
Devart.Data.Linq.Engine.ah.a(Expression A_0, Object& A_1)
Devart.Data.Linq.Engine.ah.e(Expression A_0)
Devart.Data.Linq.DataProvider.a(Expression A_0)
Devart.Data.Linq.Engine.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)


FYI, the following workaround works correctly:
Code: Select all
short id = 1;
DB.DataCurrencies.Where(c => c.Id == id).SingleOrDefault();
dilbert
 
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Re: Specified cast is not valid

Postby MariiaI » Mon 17 Sep 2012 08:23

Thank you for the report. This is a known issue, we are working on it now. We will inform when it is fixed.
As a workaround, you could use a variable of the int16 type in the query:
Code: Select all
Int16 id = 1;
DB.DataCurrencies.Where(c => c.Id == id).SingleOrDefault();
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Specified cast is not valid

Postby MariiaI » Fri 30 Nov 2012 07:48

New build of dotConnect for MySQL 7.2.132 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/mysql/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?t=25386
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for MySQL