Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecuteDeleteAsync in combination with Take throws InvalidOperationException #1919

Open
tim-stuyckens-materialise opened this issue May 7, 2024 · 0 comments

Comments

@tim-stuyckens-materialise

Steps to reproduce

    public DbSet<SyncRunItem> SyncRunItems { get; set; } = null!;
    public DbSet<SomethingPlatformPart> SomethingPlatformParts{ get; set; } = null!;

    public class SomethingPlatformPart
    {
        public Guid SyncRunItemId { get; set; }
        public SyncRunItem SyncRunItem { get; set; }
    }
    
    public class SyncRunItem
    {
       
        public DateTime StartDate { get; set; }
    }
    
    
    dbContext.SomethingPlatformParts
                    .Where(x => x.SyncRunItem.StartDate < addMonths)
                    .Take(100 * 1000)
                    .ExecuteDeleteAsync();

The issue

ExecuteDeleteAsync in combination with Take doesn't work

Message: 
System.InvalidOperationException : The operation 'ExecuteDelete' 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, please file an issue.

  Stack Trace: 
MySqlQuerySqlGenerator.VisitDelete(DeleteExpression deleteExpression)
QuerySqlGenerator.GenerateRootCommand(Expression queryExpression)
QuerySqlGenerator.GetCommand(Expression queryExpression)
RelationalCommandCache.GetRelationalCommandTemplate(IReadOnlyDictionary`2 parameters)
RelationCommandCacheExtensions.RentAndPopulateRelationalCommand(RelationalCommandCache relationalCommandCache, RelationalQueryContext queryContext)
<>c.<NonQueryResultAsync>b__14_0(DbContext _, ValueTuple`3 state, CancellationToken cancellationToken)
MySqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)

Further technical details

MySQL version:
Operating system: windows (dev machine) & linux containers
Pomelo.EntityFrameworkCore.MySql version: 8.02
Microsoft.AspNetCore.App version: 8

Other details about my project setup: works for other database providers like sqlLite, there the generated SQL is in the form of:

 DELETE FROM "SomethingPlatformParts" AS "s"
  WHERE "s"."SomethingPlatformPartId" IN (
      SELECT "s0"."SomethingPlatformPartId"
      FROM "SomethingPlatformParts" AS "s0"
      INNER JOIN "SyncRunItems" AS "s1" ON "s0"."SyncRunItemId" = "s1"."Id"
      WHERE "s1"."StartDate" < @__refMonth_0
      LIMIT @__p_1
  )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant