dotnet/efcore · error · NotSupportedException

This enumerator cannot be reset.

Error message

This enumerator cannot be reset.

What it means

Thrown when calling Reset() on the IEnumerator returned by a grouped querying enumerable (GroupBy with single-query mode). Like all EF Core query enumerators, it is forward-only because it wraps a single DbDataReader. Reset() intentionally throws NotSupportedException per IEnumerator contract.

Solutions

  1. Do not call Reset(); re-execute the GroupBy query to get fresh results.
  2. Materialize with ToList()/ToListAsync() first if you need to enumerate multiple times.
  3. File an issue with whatever library is calling Reset() on the enumerator.

Example fix

// before
var query = context.Orders.GroupBy(o => o.CustomerId);
using var e = query.GetEnumerator();
e.Reset(); // throws

// after
var groups = query.ToList();
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Calling .Reset() on an enumerator from a GroupBy LINQ query executed in single-query mode against a relational provider. Typically triggered by framework code or utility libraries that call Reset() generically.

Common situations: Third-party libraries that wrap or re-enumerate IQueryable results and call Reset(). Attempting to replay grouped results from the same enumerator without re-querying.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/0a7510d3df70d251. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Query/Internal/GroupBySingleQueryingEnumerable.cs:369

            enumerator._relationalQueryContext.InitializeStateManager(enumerator._standAloneStateManager);

            return false;
        }

        public void Dispose()
        {
            if (_dataReader is not null)
            {
                _relationalQueryContext.Connection.ReturnCommand(_relationalCommand!);
                _dataReader.Dispose();
                _dataReader = null;
                _dbDataReader = null;
            }
        }

        public void Reset()
            => throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
    }

    private sealed class AsyncEnumerator : IAsyncEnumerator<IGrouping<TKey, TElement>>
    {
        private readonly RelationalQueryContext _relationalQueryContext;
        private readonly RelationalCommandResolver _relationalCommandResolver;
        private readonly IReadOnlyList<ReaderColumn?>? _readerColumns;
        private readonly Func<QueryContext, DbDataReader, TKey> _keySelector;
        private readonly Func<QueryContext, DbDataReader, object[]> _keyIdentifier;
        private readonly IReadOnlyList<Func<object, object, bool>> _keyIdentifierValueComparers;
        private readonly Func<QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator, TElement> _elementSelector;
        private readonly Type _contextType;
        private readonly IDiagnosticsLogger<DbLoggerCategory.Query> _queryLogger;
        private readonly bool _standAloneStateManager;
        private readonly bool _detailedErrorsEnabled;
        private readonly IConcurrencyDetector? _concurrencyDetector;
        private readonly IExceptionDetector _exceptionDetector;
        private readonly CancellationToken _cancellationToken;

View on GitHub (pinned to 3a2006ef56)