Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Check on primary key field when inserting object

Since we assume an identity column anyway (we check for @@IDENTITY after insert)
let's assume that the identity column is the same as the primary key. If I insert 
a POCO the primary key column is there and thus the column is added to
the SQL insert statement. Proposed change filters the primary key column out from
the list of properties.
  • Loading branch information...
1 parent 32b0dee commit 9f162abd704cef60ec6682c63400af64b5be61c1 @mountain65 mountain65 committed
Showing with 1 addition and 1 deletion.
  1. +1 −1  Massive.cs
2  Massive.cs
@@ -427,7 +427,7 @@ private dynamic BuildPagedResult(string sql = "", string primaryKeyField = "", s
var stub = "INSERT INTO {0} ({1}) \r\n VALUES ({2})";
result = CreateCommand(stub, null);
int counter = 0;
- foreach (var item in settings) {
+ foreach (var item in settings.Where(s => s.Key != PrimaryKeyField))
sbKeys.AppendFormat("{0},", item.Key);
sbVals.AppendFormat("@{0},", counter.ToString());

0 comments on commit 9f162ab

Please sign in to comment.
Something went wrong with that request. Please try again.