Commit 1a506e8e authored by David Chell's avatar David Chell

Fixed Insert not inserting when the object had no primary key.

parent 0d9705b4
...@@ -190,25 +190,22 @@ private static string GetTableName(Type type) ...@@ -190,25 +190,22 @@ private static string GetTableName(Type type)
sb.Append(") "); sb.Append(") ");
long id = 0; long id = 0;
#if POSTGRESQL #if POSTGRESQL
if (keyProperties.Count() > 0) sb.Append(" RETURNING ");
for (var i = 0; i < keyProperties.Count(); i++)
{ {
sb.Append(" RETURNING "); var property = keyProperties.ElementAt(i);
for (var i = 0; i < keyProperties.Count(); i++) sb.Append(property.Name);
{ if (i < keyProperties.Count() - 1)
var property = keyProperties.ElementAt(i); sb.Append(", ");
sb.Append(property.Name); }
if (i < keyProperties.Count() - 1) var r = connection.Query(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout);
sb.Append(", "); // Return the key py assinging the corresponding property in the object - by product is that it supports compound primary keys
} foreach (var p in keyProperties)
var r = connection.Query(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout); {
// Return the key py assinging the corresponding property in the object - by product is that it supports compound primary keys var value = ((IDictionary<string, object>) r.First())[p.Name.ToLower()];
foreach (var p in keyProperties) p.SetValue(entityToInsert, value, null);
{ if (id == 0)
var value = ((IDictionary<string, object>) r.First())[p.Name.ToLower()]; id = Convert.ToInt64(value);
p.SetValue(entityToInsert, value, null);
if (id == 0)
id = Convert.ToInt64(value);
}
} }
#else #else
connection.Execute(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout); connection.Execute(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment