Commit 48c111ac authored by Peter Gill's avatar Peter Gill

Add SQLiteAdapter. Dapper.Contrib inserts now works with sqlite.

parent 885a8d46
...@@ -28,7 +28,8 @@ public interface IProxy ...@@ -28,7 +28,8 @@ public interface IProxy
private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary = new Dictionary<string, ISqlAdapter>() { private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary = new Dictionary<string, ISqlAdapter>() {
{"sqlconnection", new SqlServerAdapter()}, {"sqlconnection", new SqlServerAdapter()},
{"npgsqlconnection", new PostgresAdapter()} {"npgsqlconnection", new PostgresAdapter()},
{"sqliteconnection", new SQLiteAdapter()}
}; };
private static IEnumerable<PropertyInfo> KeyPropertiesCache(Type type) private static IEnumerable<PropertyInfo> KeyPropertiesCache(Type type)
...@@ -532,4 +533,23 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com ...@@ -532,4 +533,23 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
} }
return id; return id;
} }
} }
\ No newline at end of file
public class SQLiteAdapter : ISqlAdapter
{
public int Insert(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, String tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
string cmd = String.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);
connection.Execute(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout);
var r = connection.Query("select last_insert_rowid() id", transaction: transaction, commandTimeout: commandTimeout);
int id = (int)r.First().id;
if (keyProperties.Any())
keyProperties.First().SetValue(entityToInsert, id, null);
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