mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-27 03:27:02 +08:00
Give more context when the GridReader is disposed; see http://stackoverflow.com/questions/12809907/
This commit is contained in:
+3
-3
@@ -2280,7 +2280,7 @@ this IDbConnection cnn, string sql, Func<TFirst, TSecond, TThird, TFourth, TRetu
|
||||
/// </summary>
|
||||
public IEnumerable<T> Read<T>()
|
||||
{
|
||||
if (reader == null) throw new ObjectDisposedException(GetType().Name);
|
||||
if (reader == null) throw new ObjectDisposedException(GetType().FullName, "The reader has been disposed; this can happen after all data has been consumed");
|
||||
if (consumed) throw new InvalidOperationException("Each grid can only be iterated once");
|
||||
var typedIdentity = identity.ForGrid(typeof(T), gridIndex);
|
||||
CacheInfo cache = GetCacheInfo(typedIdentity);
|
||||
@@ -2298,7 +2298,6 @@ this IDbConnection cnn, string sql, Func<TFirst, TSecond, TThird, TFourth, TRetu
|
||||
|
||||
private IEnumerable<TReturn> MultiReadInternal<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>(object func, string splitOn)
|
||||
{
|
||||
|
||||
var identity = this.identity.ForGrid(typeof(TReturn), new Type[] {
|
||||
typeof(TFirst),
|
||||
typeof(TSecond),
|
||||
@@ -2413,12 +2412,13 @@ this IDbConnection cnn, string sql, Func<TFirst, TSecond, TThird, TFourth, TRetu
|
||||
}
|
||||
}
|
||||
}
|
||||
private int gridIndex;
|
||||
private int gridIndex, readCount;
|
||||
private bool consumed;
|
||||
private void NextResult()
|
||||
{
|
||||
if (reader.NextResult())
|
||||
{
|
||||
readCount++;
|
||||
gridIndex++;
|
||||
consumed = false;
|
||||
}
|
||||
|
||||
@@ -2096,6 +2096,31 @@ end");
|
||||
}
|
||||
}
|
||||
|
||||
public void TestMultiSelectWithSomeEmptyGrids()
|
||||
{
|
||||
using (var reader = connection.QueryMultiple("select 1; select 2 where 1 = 0; select 3 where 1 = 0; select 4;"))
|
||||
{
|
||||
var one = reader.Read<int>().ToArray();
|
||||
var two = reader.Read<int>().ToArray();
|
||||
var three = reader.Read<int>().ToArray();
|
||||
var four = reader.Read<int>().ToArray();
|
||||
try { // only returned four grids; expect a fifth read to fail
|
||||
reader.Read<int>();
|
||||
throw new InvalidOperationException("this should not have worked!");
|
||||
}
|
||||
catch (ObjectDisposedException ex) { // expected; success
|
||||
ex.Message.IsEqualTo("The reader has been disposed; this can happen after all data has been consumed\r\nObject name: 'Dapper.SqlMapper+GridReader'.");
|
||||
}
|
||||
|
||||
one.Length.IsEqualTo(1);
|
||||
one[0].IsEqualTo(1);
|
||||
two.Length.IsEqualTo(0);
|
||||
three.Length.IsEqualTo(0);
|
||||
four.Length.IsEqualTo(1);
|
||||
four[0].IsEqualTo(4);
|
||||
}
|
||||
}
|
||||
|
||||
class TransactedConnection : IDbConnection
|
||||
{
|
||||
IDbConnection _conn;
|
||||
|
||||
Reference in New Issue
Block a user