99using System . Threading ;
1010
1111using Dapper ;
12+ using Dapper . Contrib . Extensions ;
1213
1314namespace Dapper . Contrib . Extensions
1415{
@@ -196,7 +197,10 @@ public static T Get<T>(this IDbConnection connection, dynamic id, IDbTransaction
196197
197198 foreach ( var property in TypePropertiesCache ( type ) )
198199 {
199- var val = res [ property . Name ] ;
200+
201+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
202+
203+ var val = res [ columnAttribute == null ? property . Name : columnAttribute . Name ] ;
200204 if ( val == null ) continue ;
201205 if ( property . PropertyType . IsGenericType && property . PropertyType . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) )
202206 {
@@ -252,7 +256,9 @@ public static IEnumerable<T> GetAll<T>(this IDbConnection connection, IDbTransac
252256 var obj = ProxyGenerator . GetInterfaceProxy < T > ( ) ;
253257 foreach ( var property in TypePropertiesCache ( type ) )
254258 {
255- var val = res [ property . Name ] ;
259+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
260+
261+ var val = res [ columnAttribute == null ? property . Name : columnAttribute . Name ] ;
256262 if ( val == null ) continue ;
257263 if ( property . PropertyType . IsGenericType && property . PropertyType . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) )
258264 {
@@ -357,14 +363,7 @@ public static long Insert<T>(this IDbConnection connection, T entityToInsert, ID
357363
358364 var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
359365
360- if ( columnAttribute == null )
361- {
362- adapter . AppendColumnName ( sbColumnList , property . Name ) ; //fix for issue #336
363- }
364- else
365- {
366- adapter . AppendColumnName ( sbColumnList , columnAttribute . Name ) ;
367- }
366+ adapter . AppendColumnName ( sbColumnList , columnAttribute == null ? property . Name : columnAttribute . Name ) ;
368367
369368 if ( i < allPropertiesExceptKeyAndComputed . Count - 1 )
370369 sbColumnList . Append ( ", " ) ;
@@ -374,7 +373,10 @@ public static long Insert<T>(this IDbConnection connection, T entityToInsert, ID
374373 for ( var i = 0 ; i < allPropertiesExceptKeyAndComputed . Count ; i ++ )
375374 {
376375 var property = allPropertiesExceptKeyAndComputed [ i ] ;
377- sbParameterList . AppendFormat ( "@{0}" , property . Name ) ;
376+
377+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
378+
379+ sbParameterList . AppendFormat ( "@{0}" , columnAttribute == null ? property . Name : columnAttribute . Name ) ;
378380 if ( i < allPropertiesExceptKeyAndComputed . Count - 1 )
379381 sbParameterList . Append ( ", " ) ;
380382 }
@@ -453,15 +455,20 @@ public static bool Update<T>(this IDbConnection connection, T entityToUpdate, ID
453455 for ( var i = 0 ; i < nonIdProps . Count ; i ++ )
454456 {
455457 var property = nonIdProps [ i ] ;
456- adapter . AppendColumnNameEqualsValue ( sb , property . Name ) ; //fix for issue #336
458+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
459+
460+ adapter . AppendColumnNameEqualsValue ( sb , columnAttribute == null ? property . Name : columnAttribute . Name ) ;
457461 if ( i < nonIdProps . Count - 1 )
458462 sb . Append ( ", " ) ;
459463 }
460464 sb . Append ( " where " ) ;
461465 for ( var i = 0 ; i < keyProperties . Count ; i ++ )
462466 {
463467 var property = keyProperties [ i ] ;
464- adapter . AppendColumnNameEqualsValue ( sb , property . Name ) ; //fix for issue #336
468+
469+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
470+
471+ adapter . AppendColumnNameEqualsValue ( sb , columnAttribute == null ? property . Name : columnAttribute . Name ) ; //fix for issue #336
465472 if ( i < keyProperties . Count - 1 )
466473 sb . Append ( " and " ) ;
467474 }
@@ -518,7 +525,10 @@ public static bool Delete<T>(this IDbConnection connection, T entityToDelete, ID
518525 for ( var i = 0 ; i < keyProperties . Count ; i ++ )
519526 {
520527 var property = keyProperties [ i ] ;
521- adapter . AppendColumnNameEqualsValue ( sb , property . Name ) ; //fix for issue #336
528+
529+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
530+
531+ adapter . AppendColumnNameEqualsValue ( sb , columnAttribute == null ? property . Name : columnAttribute . Name ) ; //fix for issue #336
522532 if ( i < keyProperties . Count - 1 )
523533 sb . Append ( " and " ) ;
524534 }
@@ -599,7 +609,10 @@ public static T GetInterfaceProxy<T>()
599609 foreach ( var property in typeof ( T ) . GetProperties ( ) )
600610 {
601611 var isId = property . GetCustomAttributes ( true ) . Any ( a => a is KeyAttribute ) ;
602- CreateProperty < T > ( typeBuilder , property . Name , property . PropertyType , setIsDirtyMethod , isId ) ;
612+
613+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
614+
615+ CreateProperty < T > ( typeBuilder , columnAttribute == null ? property . Name : columnAttribute . Name , property . PropertyType , setIsDirtyMethod , isId ) ;
603616 }
604617
605618#if NETSTANDARD2_0
@@ -1037,7 +1050,10 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
10371050 if ( ! first )
10381051 sb . Append ( ", " ) ;
10391052 first = false ;
1040- sb . Append ( property . Name ) ;
1053+
1054+ var columnAttribute = property . GetCustomAttribute < ColumnAttribute > ( ) ;
1055+
1056+ sb . Append ( columnAttribute == null ? property . Name : columnAttribute . Name ) ;
10411057 }
10421058 }
10431059
0 commit comments