提交 0e4785ed 编写于 作者: S Sam Saffron

multimap was not buffered properly

上级 6bd0e24c
......@@ -163,7 +163,7 @@ public static IEnumerable<dynamic> Query(this IDbConnection cnn, string sql, dyn
public static IEnumerable<T> Query<T>(this IDbConnection cnn, string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null)
{
var data = QueryInternal<T>(cnn, sql, param as object, transaction, commandTimeout);
return (buffered) ? data.ToList() : data;
return buffered ? data.ToList() : data;
}
/// <summary>
......@@ -231,7 +231,13 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
class DontMap {}
static IEnumerable<T> MultiMap<T, U, V, Z, X>(this IDbConnection cnn, string sql, object map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null)
{
var identity = new Identity(sql, cnn, typeof(T), param == null ? null : param.GetType(), otherTypes: new[] {typeof(T), typeof(U), typeof(V), typeof(Z), typeof(X) });
var results = MultiMapImpl<T, U, V, Z, X>(cnn, sql, map, param, transaction, splitOn, commandTimeout);
return buffered ? results.ToList() : results;
}
static IEnumerable<T> MultiMapImpl<T, U, V, Z, X>(this IDbConnection cnn, string sql, object map, object param = null, IDbTransaction transaction = null, string splitOn = "Id", int? commandTimeout = null)
{
var identity = new Identity(sql, cnn, typeof(T), param == null ? null : param.GetType(), otherTypes: new[] { typeof(T), typeof(U), typeof(V), typeof(Z), typeof(X) });
var info = GetCacheInfo(param, identity);
using (var cmd = SetupCommand(cnn, transaction, sql, info.ParamReader, param, commandTimeout))
......@@ -249,7 +255,7 @@ class DontMap {}
for (pos = current + 1; pos < reader.FieldCount; pos++)
{
// some people like ID some id ... assuming case insensitive splits for now
if (string.Equals(reader.GetName(pos),splitOn,StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(reader.GetName(pos), splitOn, StringComparison.InvariantCultureIgnoreCase))
{
break;
}
......@@ -296,7 +302,7 @@ class DontMap {}
var deserializer2 = (Func<IDataReader, U>)info.OtherDeserializers[0];
Func<IDataReader,T> mapIt = null;
Func<IDataReader, T> mapIt = null;
if (info.OtherDeserializers.Length == 1)
{
......@@ -347,7 +353,7 @@ class DontMap {}
}
}
if (mapIt!=null)
if (mapIt != null)
while (reader.Read())
{
yield return mapIt(reader);
......@@ -356,6 +362,7 @@ class DontMap {}
}
}
private static CacheInfo GetCacheInfo(object param, Identity identity)
{
CacheInfo info;
......
......@@ -432,7 +432,8 @@ public void MultiRSSqlCE()
cnn.Close();
}
}
/* TODO:
*
public void TestMagicParam()
{
// magic params allow you to pass in single params without using an anon class
......@@ -441,6 +442,7 @@ public void TestMagicParam()
var first = connection.Query("select @a as a", 1).First();
Assert.IsEqualTo(first.a, 1);
}
* */
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册