{"record":{"id":"0925bec5ff067988","repo":"dotnet/efcore","slug":"this-enumerator-cannot-be-reset-0925be","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/GroupBySplitQueryingEnumerable.cs","lineNumber":383,"sourceCode":"                if (_resultCoordinator != null)\n                {\n                    foreach (var dataReader in _resultCoordinator.DataReaders)\n                    {\n                        dataReader?.DataReader.Dispose();\n                    }\n\n                    _resultCoordinator.DataReaders.Clear();\n\n                    _resultCoordinator = null;\n                }\n\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, SplitQueryResultCoordinator, TElement> _elementSelector;\n        private readonly Func<QueryContext, IExecutionStrategy, SplitQueryResultCoordinator, Task>? _relatedDataLoaders;\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;","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Query/Internal/GroupBySplitQueryingEnumerable.cs#L365-L401","documentation":"Thrown from Enumerator.Reset() on GroupBySplitQueryingEnumerable (GroupBySplitQueryingEnumerable.cs:383). This enumerator drives a split-query GroupBy that issues separate SQL per related collection, coordinating multiple forward-only readers; it cannot be rewound. Reset is unsupported by design.","triggerScenarios":"Calling IEnumerator.Reset() on an enumerator from a GroupBy query running with AsSplitQuery() (or the global UseSplitQueries). Triggered by code or libraries that re-iterate via Reset instead of re-querying.","commonSituations":"Using AsSplitQuery() for a GroupBy with includes and then passing the live enumerable to a reset-assuming helper; migrated LINQ-to-Objects code; custom aggregation helpers.","solutions":["Buffer results with ToList()/ToListAsync() and iterate the in-memory list.","Re-execute the IQueryable to get a fresh enumerator.","Avoid direct enumerator Reset calls; prefer foreach.","When a third-party component needs resettable enumeration, pass the materialized list, not the EF enumerable."],"exampleFix":"// before\nvar grouped = context.Customers\n    .AsSplitQuery()\n    .GroupBy(c => c.Region);\nusing var e = grouped.GetEnumerator();\ne.Reset(); // throws\n\n// after\nvar grouped = context.Customers\n    .AsSplitQuery()\n    .GroupBy(c => c.Region)\n    .ToList();\nusing var e = grouped.GetEnumerator(); // safe, in-memory","handlingStrategy":"validation","validationCode":"var groups = ctx.Set<T>().AsSplitQuery().GroupBy(k => k.Key).ToList(); // buffer for reuse","typeGuard":"static bool IsResettable<T>(IEnumerable<T> s) => s is IList<T> or Array;","tryCatchPattern":"try { e.Reset(); }\ncatch (NotSupportedException) {\n    var buffered = query.ToList();\n}","preventionTips":["Materialize split-query GroupBy results before re-iterating.","Avoid Reset on EF enumerators; use foreach.","Feed buffered lists to libraries requiring Reset."],"tags":["ef-core","enumerator","reset","groupby","split-query"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}