diff --git a/Dapper/SqlMapper.cs b/Dapper/SqlMapper.cs index ff3915a0..a458d86e 100644 --- a/Dapper/SqlMapper.cs +++ b/Dapper/SqlMapper.cs @@ -2280,7 +2280,7 @@ this IDbConnection cnn, string sql, Func public IEnumerable Read() { - 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 MultiReadInternal(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().ToArray(); + var two = reader.Read().ToArray(); + var three = reader.Read().ToArray(); + var four = reader.Read().ToArray(); + try { // only returned four grids; expect a fifth read to fail + reader.Read(); + 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;