@@ -1463,14 +1463,16 @@ internal static RowInfo ExecuteArrayRowReadClassOrTuple(string flagStr, Type typ
14631463 var name = row2 . GetName ( a ) ;
14641464 //expando[name] = row2.GetValue(a);
14651465 if ( expandodic . ContainsKey ( name ) ) continue ;
1466- expandodic . Add ( name , Utils . InternalDataReaderGetValue ( _commonUtils , row2 , a ) ) ;
1466+ expandodic . Add ( name , Utils . InternalDataReaderGetValue ( commonUtils2 , row2 , a ) ) ;
14671467 }
14681468 //expando = expandodic;
14691469 return new RowInfo ( expandodic , fc ) ;
14701470 } ;
14711471 return dynamicFunc ; // Expression.Lambda<Func<Type, int[], DbDataReader, int, RowInfo>>(null);
14721472 }
14731473
1474+ if ( type . IsAnonymousType ( ) ) return ExecuteArrayRowReadAnonymousType ;
1475+
14741476 //类注入属性
14751477 var typetb = GetTableByEntity ( type , _commonUtils ) ;
14761478 var retExp = Expression . Variable ( type , "ret" ) ;
@@ -1596,12 +1598,13 @@ internal static RowInfo ExecuteArrayRowReadClassOrTuple(string flagStr, Type typ
15961598 var propIndex = 0 ;
15971599 foreach ( var prop in props )
15981600 {
1599- if ( typetb . ColumnsByCsIgnore . ContainsKey ( prop . Name ) )
1601+ if ( typetb ? . ColumnsByCsIgnore . ContainsKey ( prop . Name ) == true )
16001602 {
16011603 ++ propIndex ;
16021604 continue ;
16031605 }
1604- var readType = typetb . ColumnsByCs . TryGetValue ( prop . Name , out var trycol ) ? trycol . Attribute . MapType : prop . PropertyType ;
1606+ ColumnInfo trycol = null ;
1607+ var readType = typetb ? . ColumnsByCs . TryGetValue ( prop . Name , out trycol ) == true ? trycol . Attribute . MapType : prop . PropertyType ;
16051608
16061609 var ispkExp = new List < Expression > ( ) ;
16071610 var propGetSetMethod = prop . GetSetMethod ( true ) ;
@@ -1700,6 +1703,18 @@ internal static RowInfo ExecuteArrayRowReadClassOrTuple(string flagStr, Type typ
17001703 return func ( typeOrg , indexes , row , dataIndex , _commonUtils ) ;
17011704 }
17021705
1706+ internal static RowInfo ExecuteArrayRowReadAnonymousType ( Type type2 , int [ ] indexes2 , DbDataReader row2 , int dataindex2 , CommonUtils commonUtils2 )
1707+ {
1708+ var ctor = type2 . InternalGetTypeConstructor0OrFirst ( ) ;
1709+ var ctorParms = new object [ ctor . GetParameters ( ) . Length ] ;
1710+ if ( indexes2 ? . Length != ctorParms . Length )
1711+ indexes2 = ctor . GetParameters ( ) . Select ( c => row2 . GetOrdinal ( c . Name ) ) . ToArray ( ) ;
1712+
1713+ for ( var c = 0 ; c < ctorParms . Length ; c ++ )
1714+ ctorParms [ c ] = Utils . InternalDataReaderGetValue ( commonUtils2 , row2 , indexes2 [ c ] ) ;
1715+ return new RowInfo ( ctor . Invoke ( ctorParms ) , ctorParms . Length ) ;
1716+ }
1717+
17031718 internal static MethodInfo MethodExecuteArrayRowReadClassOrTuple = typeof ( Utils ) . GetMethod ( "ExecuteArrayRowReadClassOrTuple" , BindingFlags . Static | BindingFlags . NonPublic ) ;
17041719 internal static MethodInfo MethodGetDataReaderValue = typeof ( Utils ) . GetMethod ( "GetDataReaderValue" , BindingFlags . Static | BindingFlags . NonPublic ) ;
17051720
0 commit comments