{"record":{"id":"0a7510d3df70d251","repo":"dotnet/efcore","slug":"this-enumerator-cannot-be-reset-0a7510","errorCode":null,"errorMessage":"This enumerator cannot be reset.","messagePattern":"This enumerator cannot be reset\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/Internal/GroupBySingleQueryingEnumerable.cs","lineNumber":369,"sourceCode":"\n            enumerator._relationalQueryContext.InitializeStateManager(enumerator._standAloneStateManager);\n\n            return false;\n        }\n\n        public void Dispose()\n        {\n            if (_dataReader is not null)\n            {\n                _relationalQueryContext.Connection.ReturnCommand(_relationalCommand!);\n                _dataReader.Dispose();\n                _dataReader = null;\n                _dbDataReader = null;\n            }\n        }\n\n        public void Reset()\n            => throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);\n    }\n\n    private sealed class AsyncEnumerator : IAsyncEnumerator<IGrouping<TKey, TElement>>\n    {\n        private readonly RelationalQueryContext _relationalQueryContext;\n        private readonly RelationalCommandResolver _relationalCommandResolver;\n        private readonly IReadOnlyList<ReaderColumn?>? _readerColumns;\n        private readonly Func<QueryContext, DbDataReader, TKey> _keySelector;\n        private readonly Func<QueryContext, DbDataReader, object[]> _keyIdentifier;\n        private readonly IReadOnlyList<Func<object, object, bool>> _keyIdentifierValueComparers;\n        private readonly Func<QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator, TElement> _elementSelector;\n        private readonly Type _contextType;\n        private readonly IDiagnosticsLogger<DbLoggerCategory.Query> _queryLogger;\n        private readonly bool _standAloneStateManager;\n        private readonly bool _detailedErrorsEnabled;\n        private readonly IConcurrencyDetector? _concurrencyDetector;\n        private readonly IExceptionDetector _exceptionDetector;\n        private readonly CancellationToken _cancellationToken;","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/Internal/GroupBySingleQueryingEnumerable.cs#L351-L387","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Do not call Reset(); re-execute the GroupBy query to get fresh results.","Materialize with ToList()/ToListAsync() first if you need to enumerate multiple times.","File an issue with whatever library is calling Reset() on the enumerator."],"exampleFix":"// before\nvar query = context.Orders.GroupBy(o => o.CustomerId);\nusing var e = query.GetEnumerator();\ne.Reset(); // throws\n\n// after\nvar groups = query.ToList();","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call Reset() on GroupBy query enumerators — re-execute the query instead.","Materialize grouped results with ToList()/ToListAsync() before passing to external code.","Wrap query results in List<T> or array before giving them to libraries that may call Reset()."],"tags":["enumerator","reset","groupby","forward-only"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}