Commit 2706855a authored by Sam Saffron's avatar Sam Saffron

add support for weakly typed arrays, aka object array.

parent ba4795e0
...@@ -286,41 +286,34 @@ public bool Equals(Identity other) ...@@ -286,41 +286,34 @@ public bool Equals(Identity other)
{ {
IEnumerable multiExec = (object)param as IEnumerable; IEnumerable multiExec = (object)param as IEnumerable;
Identity identity; Identity identity;
CacheInfo info; CacheInfo info = null;
if (multiExec != null && !(multiExec is string)) if (multiExec != null && !(multiExec is string))
{ // we actually want a T from IEnumerable<T> {
var interfaces = multiExec.GetType().GetInterfaces(); bool isFirst = true;
var openType = typeof(IEnumerable<>); int total = 0;
Type foundType = null; using (var cmd = SetupCommand(cnn, transaction, sql, null, null, commandTimeout, commandType))
for (int i = 0; i < interfaces.Length; i++)
{ {
if (interfaces[i].IsGenericType && interfaces[i].GetGenericTypeDefinition() == openType)
{ // implementing more than one T is self-inflicted string masterSql = null;
foundType = interfaces[i].GetGenericArguments()[0]; foreach (var obj in multiExec)
identity = new Identity(sql, cnn, null, foundType, null); {
info = GetCacheInfo(identity); if (isFirst)
using (var cmd = SetupCommand(cnn, transaction, sql, null, null, commandTimeout, commandType))
{ {
bool isFirst = true; masterSql = cmd.CommandText;
var masterSql = cmd.CommandText; isFirst = false;
var reader = info.ParamReader; identity = new Identity(sql, cnn, null, obj.GetType(), null);
int total = 0; info = GetCacheInfo(identity);
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;
} }
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 // nice and simple
......
...@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand() ...@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand()
sum.IsEqualTo(10); 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() public void TestMassiveStrings()
{ {
var str = new string('X', 20000); var str = new string('X', 20000);
......
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