Page 1 of 1

Specified cast is not valid

Posted: Fri 14 Sep 2012 15:30
by dilbert
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();

Re: Specified cast is not valid

Posted: Mon 17 Sep 2012 08:23
by MariiaI
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();

Re: Specified cast is not valid

Posted: Fri 30 Nov 2012 07:48
by MariiaI
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