private static void FlushCaches() { // Whenever a mapper is registered or revoked, we have to assume any generated code is no longer valid. // Since this should be a rare occurrence, the simplest approach is to simply dump everything and start over. MultiPocoFactory.FlushCaches(); PocoData.FlushCaches(); }
/// <summary> /// Read data to multiple pocos /// </summary> /// <typeparam name="TRet">The type of objects in the returned IEnumerable</typeparam> /// <param name="index">Reader row to be read from the underlying IDataReader</param> /// <param name="types">An array of Types representing the POCO types of the returned result set.</param> /// <param name="cb">A callback function to connect the POCO instances, or null to automatically guess the relationships</param> /// <returns>A collection of POCO's as an IEnumerable</returns> private IEnumerable <TRet> MultiPocoFromIDataReader <TRet>(int index, Type[] types, object cb) { if (_reader == null) { throw new ObjectDisposedException(GetType().FullName, "The data reader has been disposed"); } if (_consumed) { throw new InvalidOperationException( "Query results must be consumed in the correct order, and each result can only be consumed once"); } _consumed = true; try { var cmd = _command; var r = _reader; var factory = MultiPocoFactory.GetFactory <TRet>(types, cmd.Connection.ConnectionString, cmd.CommandText, r, _defaultMapper); if (cb == null) { cb = MultiPocoFactory.GetAutoMapper(types.ToArray()); } bool bNeedTerminator = false; while (true) { TRet poco; try { if (!r.Read()) { break; } poco = factory(r, cb); } catch (Exception x) { if (_db.OnException(x)) { throw; } yield break; } if (poco != null) { yield return(poco); } else { bNeedTerminator = true; } } if (bNeedTerminator) { var poco = (TRet)(cb as Delegate).DynamicInvoke(new object[types.Length]); if (poco != null) { yield return(poco); } else { yield break; } } } finally { if (index == _gridIndex) { NextResult(); } } }