@@ -9,26 +9,34 @@ public partial class Query
99 {
1010 public Query AsInsert ( object data , bool returnId = false )
1111 {
12- var dictionary = new Dictionary < string , object > ( ) ;
12+ var dictionary = BuildDictionaryOnInsert ( data ) ;
13+
14+ return AsInsert ( dictionary , returnId ) ;
15+ }
1316
14- var props = data . GetType ( )
15- . GetRuntimeProperties ( )
16- . Where ( _ => _ . GetCustomAttribute ( typeof ( IgnoreAttribute ) ) == null ) ;
1717
18- foreach ( var item in props )
18+ private Dictionary < string , object > BuildDictionaryOnInsert ( object data )
19+ {
20+
21+ var dictionary = new Dictionary < string , object > ( ) ;
22+ var props = data . GetType ( ) . GetRuntimeProperties ( ) ;
23+
24+ foreach ( PropertyInfo property in props )
1925 {
20- var attr = item . GetCustomAttribute ( typeof ( ColumnAttribute ) ) as ColumnAttribute ;
21- if ( attr != null )
22- {
23- dictionary . Add ( attr . Name , item . GetValue ( data ) ) ;
24- }
25- else
26+ if ( property . GetCustomAttribute ( typeof ( IgnoreAttribute ) ) != null )
2627 {
27- dictionary . Add ( item . Name , item . GetValue ( data ) ) ;
28+ continue ;
2829 }
30+
31+ var value = property . GetValue ( data ) ;
32+
33+ var colAttr = property . GetCustomAttribute ( typeof ( ColumnAttribute ) ) as ColumnAttribute ;
34+ var name = colAttr ? . Name ?? property . Name ;
35+
36+ dictionary . Add ( name , value ) ;
2937 }
3038
31- return AsInsert ( dictionary , returnId ) ;
39+ return dictionary ;
3240 }
3341
3442 public Query AsInsert ( IEnumerable < string > columns , IEnumerable < object > values )
0 commit comments