Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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...
commit 9f162abd704cef60ec6682c63400af64b5be61c1 1 parent 32b0dee
Richard de Zwart mountain65 authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  Massive.cs
2  Massive.cs
View
@@ -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());
result.AddParam(item.Value);
Please sign in to comment.
Something went wrong with that request. Please try again.