{"record":{"id":"bf62064123587e5d","repo":"dotnet/efcore","slug":"this-enumerator-cannot-be-reset-bf6206","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/SingleQueryingEnumerable.cs","lineNumber":296,"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<T>\n    {\n        private readonly RelationalQueryContext _relationalQueryContext;\n        private readonly RelationalCommandResolver _relationalCommandResolver;\n        private readonly IReadOnlyList<ReaderColumn?>? _readerColumns;\n        private readonly Func<QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator, T> _shaper;\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;\n\n        private IRelationalCommand? _relationalCommand;\n        private RelationalDataReader? _dataReader;","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs#L278-L314","documentation":"Thrown when calling Reset() on the IEnumerator<T> from a SingleQueryingEnumerable — the standard query enumerable for non-split relational queries. The enumerator wraps a single DbDataReader that is consumed once and cannot be rewound, so Reset() throws NotSupportedException as permitted by the IEnumerator contract.","triggerScenarios":"Calling .Reset() on the enumerator obtained from any standard LINQ-to-Entities query's GetEnumerator() (single-query mode). This is usually triggered by library code, not direct application code.","commonSituations":"A collection adapter, testing mock framework, or UI data binding component that calls Reset() on enumerators. Attempting to enumerate a query result twice with the same enumerator handle.","solutions":["Do not call Reset(); re-execute the LINQ query for a fresh enumeration.","Materialize with ToList()/ToListAsync() if multiple passes are needed.","Report the Reset() call to the library or framework that makes it."],"exampleFix":"// before\nusing var e = context.Blogs.Where(b => b.Active).GetEnumerator();\ne.Reset(); // throws\n\n// after\nvar blogs = context.Blogs.Where(b => b.Active).ToList();","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call Reset() on EF Core query enumerators — re-execute the query for fresh results.","Materialize results with ToList()/ToListAsync() before passing to libraries or data-binding frameworks.","Document that EF enumerators are forward-only in your codebase."],"tags":["enumerator","reset","single-query","forward-only"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}