Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Dapper.SimpleCRUD/SimpleCRUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static void StringBuilderCache(StringBuilder sb, string cacheKey, Action
StringBuilderCacheDict.AddOrUpdate(cacheKey, value, (t, v) => value);
sb.Append(value);
}

/// <summary>
/// Returns the current dialect name
/// </summary>
Expand All @@ -76,7 +76,7 @@ public static void SetDialect(Dialect dialect)
case Dialect.PostgreSQL:
_dialect = Dialect.PostgreSQL;
_encapsulation = "\"{0}\"";
_getIdentitySql = string.Format("SELECT LASTVAL() AS id");
_getIdentitySql = "RETURNING {0} AS id";
_getPagedListSql = "Select {SelectColumns} from {TableName} {WhereClause} Order By {OrderBy} LIMIT {RowsPerPage} OFFSET (({PageNumber}-1) * {RowsPerPage})";
break;
case Dialect.SQLite:
Expand Down Expand Up @@ -359,9 +359,9 @@ public static TKey Insert<TKey, TEntity>(this IDbConnection connection, TEntity
if (typeof(TEntity).IsInterface) //FallBack to BaseType Generic Method : https://stackoverflow.com/questions/4101784/calling-a-generic-method-with-a-dynamic-type
{
return (TKey)typeof(SimpleCRUD)
.GetMethods().Where(methodInfo=>methodInfo.Name == nameof(Insert) && methodInfo.GetGenericArguments().Count()==2).Single()
.GetMethods().Where(methodInfo => methodInfo.Name == nameof(Insert) && methodInfo.GetGenericArguments().Count() == 2).Single()
.MakeGenericMethod(new Type[] { typeof(TKey), entityToInsert.GetType() })
.Invoke(null, new object[] { connection,entityToInsert,transaction,commandTimeout });
.Invoke(null, new object[] { connection, entityToInsert, transaction, commandTimeout });
}
var idProps = GetIdProperties(entityToInsert).ToList();

Expand Down Expand Up @@ -405,7 +405,15 @@ public static TKey Insert<TKey, TEntity>(this IDbConnection connection, TEntity

if ((keytype == typeof(int) || keytype == typeof(long)) && Convert.ToInt64(idProps.First().GetValue(entityToInsert, null)) == 0)
{
sb.Append(";" + _getIdentitySql);
switch (_dialect)
{
case (Dialect.PostgreSQL):
sb.Append(" " + string.Format(_getIdentitySql, GetColumnName(idProps.First())));
break;
default:
sb.Append(";" + _getIdentitySql);
break;
}
}
else
{
Expand Down Expand Up @@ -1264,6 +1272,6 @@ public static bool IsSimpleType(this Type type)

public static string CacheKey(this IEnumerable<PropertyInfo> props)
{
return string.Join(",",props.Select(p=> p.DeclaringType.FullName + "." + p.Name).ToArray());
return string.Join(",", props.Select(p => p.DeclaringType.FullName + "." + p.Name).ToArray());
}
}