1

Resolved

Anito.Data.DataSession Count<T>() method throws specified cast is not valid exception

description

Anito.Data.DataSession Count<T>() method throws specified cast is not valid exception when using Anito.Data.MySqlClient as the Provider.
 
Cause:
Anito.Data.MySqlClient.MySqlProvider.ExecuteScalar, returns a decimal type result for the count command text in mysql. C#.net current version can't cast a decimal type to type int. Refer to http://forums.asp.net/t/694702.aspx/1?ExecuteScalar+gets+Specified+cast+is+not+valid+error for more information.
 
Screencast:
http://www.screencast.com/t/XlUicQ8tBflV

comments

mdcuesta wrote Mar 22, 2011 at 4:29 AM

Assigned

mdcuesta wrote Mar 22, 2011 at 4:58 AM

Proposed Solution:

I added 2 additional methods to be implemented in Anito.Data.IProvider
int ExecuteCount(ICommand command);
int ExecuteCount(ICommand command, ITransaction transaction);

Every provider should implement those methods that will handle the count command, instead of using IProvider.ExecuteScalar.

We cannot afford to sacrifice performance in DataSession.Count(), just to check if the returned obect is of integer type or decimal type then parse to int. It's safer to let the provider returned the integer type result of the count command.

I already modified Anito.Data.IProvider and Anito.Data.DataSession, to use the 2 methods added.

wrote Mar 22, 2011 at 5:12 AM

wrote Mar 23, 2011 at 4:21 AM

mdcuesta wrote Apr 6, 2011 at 5:01 AM

Methods implemented in both providers



** Closed by mdcuesta 3/22/2011 9:21 PM

mdcuesta wrote Apr 6, 2011 at 5:01 AM

Reopened to edit assigned release

mdcuesta wrote Apr 6, 2011 at 5:01 AM

assigned release to anito.net-alpha-1.0.1.1

closed

wrote Apr 6, 2011 at 5:02 AM

wrote Apr 14, 2011 at 5:31 AM

zero1ne wrote Apr 15, 2011 at 6:06 AM

returned *object

wrote Feb 13, 2013 at 6:14 PM

wrote May 15, 2013 at 11:16 PM

wrote May 15, 2013 at 11:16 PM

wrote Jun 14, 2013 at 7:01 AM