File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1266,18 +1266,25 @@ public int Insert(object obj, string? modifier = null) {
12661266 }
12671267 }
12681268
1269- object ? [ ] values = new object [ map . Columns . Length ] ;
1269+ TableMapping . Column [ ] columns = map . Columns ;
1270+
1271+ // Don't insert auto-incremented columns (unless "OR REPLACE"/"OR IGNORE")
1272+ if ( string . IsNullOrEmpty ( modifier ) ) {
1273+ columns = [ .. columns . Where ( column => ! column . AutoIncrement ) ] ;
1274+ }
1275+
1276+ object ? [ ] values = new object [ columns . Length ] ;
12701277 for ( int i = 0 ; i < values . Length ; i ++ ) {
1271- values [ i ] = map . Columns [ i ] . GetValue ( obj ) ;
1278+ values [ i ] = columns [ i ] . GetValue ( obj ) ;
12721279 }
12731280
12741281 string query ;
1275- if ( map . Columns . Length == 0 ) {
1282+ if ( columns . Length == 0 ) {
12761283 query = $ "insert { modifier } into \" { map . TableName } \" default values";
12771284 }
12781285 else {
1279- string columnsSql = string . Join ( "," , map . Columns . Select ( column => "\" " + column . Name + "\" " ) ) ;
1280- string valuesSql = string . Join ( "," , map . Columns . Select ( column => "?" ) ) ;
1286+ string columnsSql = string . Join ( "," , columns . Select ( column => "\" " + column . Name + "\" " ) ) ;
1287+ string valuesSql = string . Join ( "," , columns . Select ( column => "?" ) ) ;
12811288 query = $ "insert { modifier } into \" { map . TableName } \" ({ columnsSql } ) values ({ valuesSql } )";
12821289 }
12831290
You can’t perform that action at this time.
0 commit comments