Commit 5633d879 authored by David Chell's avatar David Chell

Reinstated support for Sql server using #define.

Signed-off-by: 's avatarDavid Chell <david@qualitech.co.nz>
parent 64666d5c
using System; #define POSTGRESQL
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
...@@ -174,9 +176,11 @@ private static string GetTableName(Type type) ...@@ -174,9 +176,11 @@ private static string GetTableName(Type type)
if (i < allPropertiesExceptKey.Count() - 1) if (i < allPropertiesExceptKey.Count() - 1)
sb.Append(", "); sb.Append(", ");
} }
long id = 0;
#if POSTGRESQL
sb.Append(") RETURNING * "); sb.Append(") RETURNING * ");
var r = connection.Query(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout); var r = connection.Query(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout);
long id = 0; // 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) foreach (var p in keyProperties)
{ {
var value = ((IDictionary<string, object>)r.First())[p.Name.ToLower()]; var value = ((IDictionary<string, object>)r.First())[p.Name.ToLower()];
...@@ -184,6 +188,13 @@ private static string GetTableName(Type type) ...@@ -184,6 +188,13 @@ private static string GetTableName(Type type)
if (id == 0) if (id == 0)
id = Convert.ToInt64(value); id = Convert.ToInt64(value);
} }
#else
sb.Append(") ");
connection.Execute(sb.ToString(), entityToInsert, transaction: transaction, commandTimeout: commandTimeout);
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
var r = connection.Query("select @@IDENTITY id", transaction: transaction, commandTimeout: commandTimeout);
id = (int)r.First().id;
#endif
return id; return id;
} }
......
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