Ejemplo n.º 1
0
 void IDisposable.Dispose()
 {
     _current = default(TEntity);
     _mapper.TearDown();
     _source.Dispose();
     _disposing?.Invoke(_count);
     _source = null;
 }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected IEnumerator <TEntity> CreateEnumerator(IDbCommand command)
        {
            var sw         = Stopwatch.StartNew();
            var connection = command.Connection;

            if (connection == null)
            {
                throw new InvalidOperationException("command.Connection is null.");
            }
            var connectionState = connection.State;

            if (connectionState != ConnectionState.Open)
            {
                connection.Open();
                Log($"  Open connection at {DateTime.Now}. Elpased times: {sw.Elapsed}.");
                sw.Restart();
            }
            var reader = command.ExecuteReader();
            {
                IResultSource source = new DataReaderResultSource(reader);
                try
                {
                    return(new QueryResultEnumerator(source, _mapper, (count) =>
                    {
                        sw.Stop();
                        Log($"  Complete enumerate {count} records. Elpased times: {sw.Elapsed}.");
                        if (connectionState != ConnectionState.Open && connection.State == ConnectionState.Closed)
                        {
                            Log($"  Close connection at {DateTime.Now}.");
                        }
                    }));
                }
                catch
                {
                    _mapper.TearDown();
                    source.Dispose();
                    sw.Stop();
                    throw;
                }
                finally
                {
                    Log("  Elapsed times: " + sw.Elapsed);
                }
            }
        }