提交 70a9c31b 编写于 作者: M Marc Gravell
......@@ -3231,8 +3231,9 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var dbType = param.DbType;
var val = param.Value;
string name = Clean(param.Name);
var isCustomQueryParameter = typeof(SqlMapper.ICustomQueryParameter).IsAssignableFrom(val.GetType());
if (dbType == null && val != null) dbType = SqlMapper.LookupDbType(val.GetType(), name);
if (dbType == null && val != null && !isCustomQueryParameter) dbType = SqlMapper.LookupDbType(val.GetType(), name);
if (dbType == DynamicParameters.EnumerableMultiParameter)
{
......@@ -3240,6 +3241,10 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
SqlMapper.PackListParameters(command, name, val);
#pragma warning restore 612, 618
}
else if (isCustomQueryParameter)
{
((SqlMapper.ICustomQueryParameter)val).AddParameter(command, name);
}
else
{
......@@ -3729,4 +3734,4 @@ public partial class FeatureSupport
#endif
}
\ No newline at end of file
}
......@@ -29,7 +29,8 @@ public interface IProxy
private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary = new Dictionary<string, ISqlAdapter>() {
{"sqlconnection", new SqlServerAdapter()},
{"npgsqlconnection", new PostgresAdapter()}
{"npgsqlconnection", new PostgresAdapter()},
{"sqliteconnection", new SQLiteAdapter()}
};
private static IEnumerable<PropertyInfo> ComputedPropertiesCache(Type type)
{
......@@ -551,4 +552,23 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
}
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册