diff --git a/Dapper.Contrib/SqlMapperExtensions.cs b/Dapper.Contrib/SqlMapperExtensions.cs index 11c947b26..0ca0087b4 100644 --- a/Dapper.Contrib/SqlMapperExtensions.cs +++ b/Dapper.Contrib/SqlMapperExtensions.cs @@ -49,6 +49,7 @@ private static readonly Dictionary AdapterDictionary {"npgsqlconnection", new PostgresAdapter()}, {"sqliteconnection", new SQLiteAdapter()}, {"mysqlconnection", new MySqlAdapter()}, + {"fbconnection", new FbAdapter() } }; private static List ComputedPropertiesCache(Type type) @@ -864,3 +865,35 @@ public void AppendColumnNameEqualsValue(StringBuilder sb, string columnName) sb.AppendFormat("\"{0}\" = @{1}", columnName, columnName); } } + +public partial class FbAdapter : ISqlAdapter +{ + public int Insert(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable keyProperties, object entityToInsert) + { + var cmd = $"insert into {tableName} ({columnList}) values ({parameterList})"; + connection.Execute(cmd, entityToInsert, transaction, commandTimeout); + + var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray(); + var keyName = propertyInfos.First().Name; + var r = connection.Query($"SELECT FIRST 1 {keyName} ID FROM {tableName} ORDER BY {keyName} DESC", transaction: transaction, commandTimeout: commandTimeout); + + var id = r.First().ID; + if (id == null) return 0; + if (!propertyInfos.Any()) return Convert.ToInt32(id); + + var idp = propertyInfos.First(); + idp.SetValue(entityToInsert, Convert.ChangeType(id, idp.PropertyType), null); + + return Convert.ToInt32(id); + } + + public void AppendColumnName(StringBuilder sb, string columnName) + { + sb.AppendFormat("{0}", columnName); + } + + public void AppendColumnNameEqualsValue(StringBuilder sb, string columnName) + { + sb.AppendFormat("{0} = @{1}", columnName, columnName); + } +} \ No newline at end of file