提交 7a1840b9 编写于 作者: S Sam Saffron

add support for weakly typed arrays, aka object array.

上级 f9670d28
......@@ -286,41 +286,34 @@ public bool Equals(Identity other)
{
IEnumerable multiExec = (object)param as IEnumerable;
Identity identity;
CacheInfo info;
CacheInfo info = null;
if (multiExec != null && !(multiExec is string))
{ // we actually want a T from IEnumerable<T>
var interfaces = multiExec.GetType().GetInterfaces();
var openType = typeof(IEnumerable<>);
Type foundType = null;
for (int i = 0; i < interfaces.Length; i++)
{
bool isFirst = true;
int total = 0;
using (var cmd = SetupCommand(cnn, transaction, sql, null, null, commandTimeout, commandType))
{
if (interfaces[i].IsGenericType && interfaces[i].GetGenericTypeDefinition() == openType)
{ // implementing more than one T is self-inflicted
foundType = interfaces[i].GetGenericArguments()[0];
identity = new Identity(sql, cnn, null, foundType, null);
info = GetCacheInfo(identity);
using (var cmd = SetupCommand(cnn, transaction, sql, null, null, commandTimeout, commandType))
string masterSql = null;
foreach (var obj in multiExec)
{
if (isFirst)
{
bool isFirst = true;
var masterSql = cmd.CommandText;
var reader = info.ParamReader;
int total = 0;
foreach (var obj in multiExec)
{
if (isFirst) { isFirst = false; }
else
{
cmd.CommandText = masterSql; // because we do magic replaces on "in" etc
cmd.Parameters.Clear(); // current code is Add-tastic
}
reader(cmd, obj);
total += cmd.ExecuteNonQuery();
}
return total;
masterSql = cmd.CommandText;
isFirst = false;
identity = new Identity(sql, cnn, null, obj.GetType(), null);
info = GetCacheInfo(identity);
}
else
{
cmd.CommandText = masterSql; // because we do magic replaces on "in" etc
cmd.Parameters.Clear(); // current code is Add-tastic
}
info.ParamReader(cmd, obj);
total += cmd.ExecuteNonQuery();
}
}
return total;
}
// nice and simple
......
......@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand()
sum.IsEqualTo(10);
}
public void TestExecuteMultipleCommandObjectArray()
{
connection.Execute("create table #t(i int)");
int tally = connection.Execute(@"insert #t (i) values(@a)", new object[] { new { a = 1 }, new { a = 2 }, new { a = 3 }, new { a = 4 } });
int sum = connection.Query<int>("select sum(i) from #t drop table #t").First();
tally.IsEqualTo(4);
sum.IsEqualTo(10);
}
public void TestMassiveStrings()
{
var str = new string('X', 20000);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册