1818
1919using DbObjectExecutor . Extensions ;
2020using DbObjectExecutor . Helpers ;
21+ using DbObjectExecutor . Mapper . Models ;
2122using System ;
2223using System . Collections . Concurrent ;
2324using System . Collections . Generic ;
2425using System . Data . Common ;
2526using System . Linq ;
26- using System . Reflection ;
2727using System . Threading ;
2828using System . Threading . Tasks ;
2929
@@ -206,40 +206,48 @@ private ReaderProperty[] MapColumnsToProperties()
206206 var sourceType = typeof ( T ) ;
207207 var columns = new string [ _reader . FieldCount ] ;
208208
209- var props = sourceType . GetPropertyInfos ( ) . ToArray ( ) ;
209+ var sourcePropertyInfo = new List < PropertyMapDto > ( sourceType . GetPropertyInfos ( ) . WithIndex ( )
210+ . Select ( x => new PropertyMapDto ( )
211+ {
212+ SourceName = x . item . Name ,
213+ Property = x . item ,
214+ AttributeName = DbObjectColumnAttributeHelper . GetDbObjectColumnName ( x . item ) ,
215+ IsInResponse = false
216+ } ) ) ;
210217
211- for ( var i = 0 ; i < _reader . FieldCount ; ++ i )
212- {
213- var attributeColumnName = DbObjectColumnAttributeHelper . GetDbObjectColumnName ( props [ i ] ) ;
214218
215- columns [ i ] = attributeColumnName . IsNullOrEmpty ( ) ? _reader . GetName ( i ) : attributeColumnName ;
219+ for ( var i = 0 ; i < _reader . FieldCount ; i ++ )
220+ {
221+ var columnName = _reader . GetName ( i ) ;
222+ columns [ i ] = columnName ;
223+ var sourceProp = sourcePropertyInfo . FirstOrDefault ( x => x . AttributeName == columnName ) ;
224+ if ( sourceProp . IsNotNull ( ) )
225+ {
226+ sourceProp ! . IsInResponse = true ;
227+ }
216228 }
217229
230+ // Create result property list hash
218231 var propKey = ComputePropertyKey ( columns ) ;
219232 if ( PropertiesCache . TryGetValue ( propKey , out var propValue ) )
220233 return propValue ;
221234
222- var properties = new List < ReaderProperty > ( columns . Length ) ;
235+ var properties = new ReaderProperty [ columns . Length ] ;
223236 for ( var i = 0 ; i < columns . Length ; i ++ )
224237 {
225- PropertyInfo prop ;
226- var propAttributeSource = sourceType . GetPropertyByName ( columns [ i ] . Replace ( "_" , "" ) ) ;
227- var propSource = sourceType . GetPropertyByName ( props [ i ] . Name . Replace ( "_" , "" ) ) ;
228-
229- if ( propSource . IsNull ( ) && propAttributeSource . IsNull ( ) )
230- continue ;
231- else
232- prop = propSource . IsNull ( ) ? propAttributeSource : propSource ;
233-
234- var setter = ( Action < object , object > ) ExpressionBuildHelper . BuildPropertySetter ( prop ) ;
235-
236- properties . Add ( new ReaderProperty { Idx = i , Setter = setter , Name = prop . Name } ) ;
238+ var property = sourcePropertyInfo . FirstOrDefault ( x => x . AttributeName == columns [ i ] . Replace ( "_" , "" )
239+ && x . IsInResponse . IsTrue ( ) ) ;
240+ if ( property . IsNotNull ( ) )
241+ {
242+ var setter = ( Action < object , object > ) ExpressionBuildHelper . BuildPropertySetter ( property ! . Property ) ;
243+
244+ properties [ i ] = new ReaderProperty { Idx = i , Setter = setter , Name = property . SourceName } ;
245+ }
237246 }
238247
239- var propertiesArray = properties . ToArray ( ) ;
240- PropertiesCache [ propKey ] = propertiesArray ;
248+ PropertiesCache [ propKey ] = properties ;
241249
242- return propertiesArray ;
250+ return properties ;
243251 }
244252 }
245253}
0 commit comments