dotnet/efcore · error · InvalidOperationException

The operation '{operation}' contains a select expression fea

Error message

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.

What it means

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.

Source

Thrown at src/EFCore.Relational/Query/QuerySqlGenerator.cs:231

                Orderings: [],
                Offset: null,
                Limit: null
            }
            && table.Equals(deleteExpression.Table))
        {
            _relationalCommandBuilder.Append("DELETE FROM ");
            Visit(deleteExpression.Table);

            if (selectExpression.Predicate != null)
            {
                _relationalCommandBuilder.AppendLine().Append("WHERE ");
                Visit(selectExpression.Predicate);
            }

            return deleteExpression;
        }

        throw new InvalidOperationException(
            RelationalStrings.ExecuteOperationWithUnsupportedOperatorInSqlGeneration(
                nameof(EntityFrameworkQueryableExtensions.ExecuteDelete)));
    }

    /// <summary>
    ///     Generates SQL for a SELECT expression.
    /// </summary>
    /// <param name="selectExpression">The <see cref="SelectExpression" /> for which to generate SQL.</param>
    protected virtual Expression VisitSelect(SelectExpression selectExpression)
    {
        IDisposable? subQueryIndent = null;
        if (selectExpression.Alias != null)
        {
            _relationalCommandBuilder.AppendLine("(");
            subQueryIndent = _relationalCommandBuilder.Indent();
        }

        if (!TryGenerateWithoutWrappingSelect(selectExpression))

View on GitHub (pinned to 3a2006ef56)

Solutions

  1. Simplify the ExecuteDelete predicate to avoid unsupported features (remove subqueries, joins, or set operations from the WHERE clause).
  2. Split into multiple simpler ExecuteDelete calls or use raw SQL for the delete.
  3. Report the bug to the provider maintainer (or EF Core at https://aka.ms/efcorefeedback) with the full query.
  4. If using a third-party provider, check for an updated version that fixes the SQL generation gap.

Example fix

// before — ExecuteDelete with complex predicate the generator can't handle
await context.Blogs
    .Where(b => b.Posts.Any(p => p.Tags.Any(t => t.Name == "old")))
    .ExecuteDeleteAsync();

// after — break into steps or use raw SQL
var blogIds = await context.Blogs
    .Where(b => b.Posts.Any(p => p.Tags.Any(t => t.Name == "old")))
    .Select(b => b.Id)
    .ToListAsync();
await context.Blogs
    .Where(b => blogIds.Contains(b.Id))
    .ExecuteDeleteAsync();
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    await context.Blogs.Where(b => b.SomeCondition).ExecuteDeleteAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("select expression feature that isn't supported"))
{
    logger.LogError(ex, "ExecuteDelete SQL generation gap — simplify predicate or use raw SQL");
    // Fallback: use raw SQL or split the operation
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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