@@ -50,16 +50,16 @@ public IEnumerable<IDictionary<string, object>> InsertMany(string tableName, IEn
5050 public IDictionary < string , object > Insert ( string tableName , IEnumerable < KeyValuePair < string , object > > data , bool resultRequired )
5151 {
5252 var table = _adapter . GetSchema ( ) . FindTable ( tableName ) ;
53-
54- CheckInsertablePropertiesAreAvailable ( table , data ) ;
53+ var dataArray = data . ToArray ( ) ;
54+ CheckInsertablePropertiesAreAvailable ( table , dataArray ) ;
5555
5656 var customInserter = _adapter . ProviderHelper . GetCustomProvider < ICustomInserter > ( _adapter . ConnectionProvider ) ;
5757 if ( customInserter != null )
5858 {
59- return customInserter . Insert ( _adapter , tableName , data . ToDictionary ( ) , _transaction ) ;
59+ return customInserter . Insert ( _adapter , tableName , dataArray . ToDictionary ( ) , _transaction ) ;
6060 }
6161
62- var dataDictionary = data . Where ( kvp => table . HasColumn ( kvp . Key ) && ! table . FindColumn ( kvp . Key ) . IsIdentity )
62+ var dataDictionary = dataArray . Where ( kvp => table . HasColumn ( kvp . Key ) && table . FindColumn ( kvp . Key ) . IsWriteable )
6363 . ToDictionary ( kvp => table . FindColumn ( kvp . Key ) , kvp => kvp . Value ) ;
6464
6565 string columnList = dataDictionary . Keys . Select ( c => c . QuotedName ) . Aggregate ( ( agg , next ) => agg + "," + next ) ;
@@ -83,11 +83,8 @@ public IDictionary<string, object> Insert(string tableName, IEnumerable<KeyValue
8383 insertSql += "; " + selectSql ;
8484 return ExecuteSingletonQuery ( insertSql , dataDictionary . Keys , dataDictionary . Values ) ;
8585 }
86- else
87- {
88- return ExecuteSingletonQuery ( insertSql , selectSql , dataDictionary . Keys ,
89- dataDictionary . Values ) ;
90- }
86+ return ExecuteSingletonQuery ( insertSql , selectSql , dataDictionary . Keys ,
87+ dataDictionary . Values ) ;
9188 }
9289 }
9390 }
0 commit comments