{"record":{"id":"48b004021f2bde89","repo":"dotnet/efcore","slug":"the-operation-operation-contains-a-select-expr","errorCode":null,"errorMessage":"The operation '{operation}' contains a select expression feature that isn't supported in the query SQL generator, but has been declared as supported by provider during translation phase. This is a bug in your EF Core provider, file an issue at https://aka.ms/efcorefeedback.","messagePattern":"The operation '(.+?)' contains a select expression feature that isn't supported in the query SQL generator, but has been declared as supported by provider during translation phase\\. This is a bug in your EF Core provider, file an issue at https://aka\\.ms/efcorefeedback\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/QuerySqlGenerator.cs","lineNumber":231,"sourceCode":"                Orderings: [],\n                Offset: null,\n                Limit: null\n            }\n            && table.Equals(deleteExpression.Table))\n        {\n            _relationalCommandBuilder.Append(\"DELETE FROM \");\n            Visit(deleteExpression.Table);\n\n            if (selectExpression.Predicate != null)\n            {\n                _relationalCommandBuilder.AppendLine().Append(\"WHERE \");\n                Visit(selectExpression.Predicate);\n            }\n\n            return deleteExpression;\n        }\n\n        throw new InvalidOperationException(\n            RelationalStrings.ExecuteOperationWithUnsupportedOperatorInSqlGeneration(\n                nameof(EntityFrameworkQueryableExtensions.ExecuteDelete)));\n    }\n\n    /// <summary>\n    ///     Generates SQL for a SELECT expression.\n    /// </summary>\n    /// <param name=\"selectExpression\">The <see cref=\"SelectExpression\" /> for which to generate SQL.</param>\n    protected virtual Expression VisitSelect(SelectExpression selectExpression)\n    {\n        IDisposable? subQueryIndent = null;\n        if (selectExpression.Alias != null)\n        {\n            _relationalCommandBuilder.AppendLine(\"(\");\n            subQueryIndent = _relationalCommandBuilder.Indent();\n        }\n\n        if (!TryGenerateWithoutWrappingSelect(selectExpression))","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/QuerySqlGenerator.cs#L213-L249","documentation":"Thrown by QuerySqlGenerator.VisitDelete when the DELETE operation's underlying SelectExpression contains a feature that the SQL generator cannot express, despite the provider's translator having declared it supported. The error message explicitly states this is a bug in the EF Core provider: translation and SQL generation capabilities are out of sync for ExecuteDelete.","triggerScenarios":"Calling ExecuteDelete (e.g., context.Blogs.Where(b => b.SomeCondition).ExecuteDeleteAsync()) where the WHERE clause or table source uses a feature the provider's translator claims to support but its SQL generator doesn't implement for DELETE statements. For example: CTEs, certain joins, or set operations inside the predicate that translate fine for SELECT but not for the DELETE FROM ... WHERE pattern.","commonSituations":"Third-party provider with incomplete ExecuteDelete SQL generation. Complex ExecuteDelete predicates involving subqueries, joins, or provider-specific features. EF Core version mismatch between translation capabilities and SQL generation.","solutions":["Simplify the ExecuteDelete predicate to avoid unsupported features (remove subqueries, joins, or set operations from the WHERE clause).","Split into multiple simpler ExecuteDelete calls or use raw SQL for the delete.","Report the bug to the provider maintainer (or EF Core at https://aka.ms/efcorefeedback) with the full query.","If using a third-party provider, check for an updated version that fixes the SQL generation gap."],"exampleFix":"// before — ExecuteDelete with complex predicate the generator can't handle\nawait context.Blogs\n    .Where(b => b.Posts.Any(p => p.Tags.Any(t => t.Name == \"old\")))\n    .ExecuteDeleteAsync();\n\n// after — break into steps or use raw SQL\nvar blogIds = await context.Blogs\n    .Where(b => b.Posts.Any(p => p.Tags.Any(t => t.Name == \"old\")))\n    .Select(b => b.Id)\n    .ToListAsync();\nawait context.Blogs\n    .Where(b => blogIds.Contains(b.Id))\n    .ExecuteDeleteAsync();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await context.Blogs.Where(b => b.SomeCondition).ExecuteDeleteAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"select expression feature that isn't supported\"))\n{\n    logger.LogError(ex, \"ExecuteDelete SQL generation gap — simplify predicate or use raw SQL\");\n    // Fallback: use raw SQL or split the operation\n    throw;\n}","preventionTips":["Keep ExecuteDelete predicates simple — avoid subqueries, joins, and set operations.","Test ExecuteDelete with complex predicates against your provider in integration tests.","Have a raw SQL fallback ready for delete operations that exceed provider SQL generation capabilities.","Report provider SQL generation gaps with a minimal repro."],"tags":["execute-delete","sql-generation","provider-bug","internal-error"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}