11using System ;
22using System . Collections . Generic ;
33using System . Threading . Tasks ;
4+ using SmartSql . Exceptions ;
45using SmartSql . Reflection . TypeConstants ;
56using SmartSql . TypeHandlers ;
67
@@ -17,7 +18,7 @@ public bool CanDeserialize(ExecutionContext executionContext, Type resultType, b
1718 public TResult ToSingle < TResult > ( ExecutionContext executionContext )
1819 {
1920 var dataReader = executionContext . DataReaderWrapper ;
20- if ( ! dataReader . HasRows ) return default ( TResult ) ;
21+ if ( ! dataReader . HasRows ) return default ;
2122 dataReader . Read ( ) ;
2223 return TypeHandlerCache < TResult , AnyFieldType > . Handler . GetValue ( dataReader , VALUE_ORDINAL , executionContext . Result . ResultType ) ; ;
2324 }
@@ -28,6 +29,16 @@ public IList<TResult> ToList<TResult>(ExecutionContext executionContext)
2829 if ( ! dataReader . HasRows ) return list ;
2930
3031 var typeHandler = TypeHandlerCache < TResult , AnyFieldType > . Handler ;
32+
33+ var resultType = typeof ( TResult ) ;
34+ if ( typeHandler == null )
35+ {
36+ typeHandler =
37+ ( ITypeHandler < TResult , AnyFieldType > ) executionContext . SmartSqlConfig . TypeHandlerFactory
38+ . GetTypeHandler ( resultType ) ??
39+ throw new SmartSqlException ( $ "Not Find TypeHandler.Type:{ resultType . FullName } .") ;
40+ }
41+
3142 while ( dataReader . Read ( ) )
3243 {
3344 var val = typeHandler . GetValue ( dataReader , VALUE_ORDINAL , executionContext . Result . ResultType ) ;
@@ -39,7 +50,7 @@ public IList<TResult> ToList<TResult>(ExecutionContext executionContext)
3950 public async Task < TResult > ToSingleAsync < TResult > ( ExecutionContext executionContext )
4051 {
4152 var dataReader = executionContext . DataReaderWrapper ;
42- if ( ! dataReader . HasRows ) return default ( TResult ) ;
53+ if ( ! dataReader . HasRows ) return default ;
4354 await dataReader . ReadAsync ( ) ;
4455 return TypeHandlerCache < TResult , AnyFieldType > . Handler . GetValue ( dataReader , VALUE_ORDINAL , executionContext . Result . ResultType ) ;
4556 }
0 commit comments