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

ExecuteDelete could not be translated #30185

Closed
verdie-g opened this issue Jan 31, 2023 · 3 comments
Closed

ExecuteDelete could not be translated #30185

verdie-g opened this issue Jan 31, 2023 · 3 comments
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported

Comments

@verdie-g
Copy link

verdie-g commented Jan 31, 2023

using Microsoft.EntityFrameworkCore;

await using var db = new MyDbContext();
await db.Entities.ExecuteDeleteAsync();

class MyDbContext : DbContext
{
    public DbSet<MyEntity> Entities { get; set; }
    
    protected override void OnConfiguring(DbContextOptionsBuilder options) =>
        options.UseInMemoryDatabase("test");
}

public class MyEntity
{
    public int Id { get; set; }
}
Unhandled exception. System.InvalidOperationException: The LINQ expression 'DbSet<MyEntity>()
    .ExecuteDelete()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/f
wlink/?linkid=2101038 for more information.
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.ExecuteDeleteAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in Program.cs:line 4
   at Program.<Main>$(String[] args) in Program.cs:line 4
   at Program.<Main>(String[] args)

EF Core version: 7.0.2
Database provider: Microsoft.EntityFrameworkCore.InMemory
Target framework: .NET 7.0
Operating system: Windows

@ajcvickers
Copy link
Member

ExecuteUpdate and ExecuteDelete are not supported by the in-memory database.

We recommend against using the in-memory provider for testing--see Testing EF Core Applications. While we have no plans to remove the in-memory provider, we will not be adding any new features to this provider because we believe valuable development time is better spent in other areas. When feasible, we plan to still fix regressions in existing behavior.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2023
@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Jan 31, 2023
@NoskovEugene
Copy link

I'm using in-memory database provider in my unit tests. And when I'm using in my buisness logic 'executeDelete', I can't test this code. It happens because you decided to not adding support for this extension method. Maybe you can change your desicion?

@roji
Copy link
Member

roji commented Aug 7, 2024

@NoskovEugene this is not something we plan to change. As @ajcvickers wrote above, there are many features of real databases that the InMemory provider can never support, and we discourage its use for testing. Consider using testcontainer.net to execute tests against your your real production system (e.g. SQL Server). See our testing docs for more info on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported
Projects
None yet
Development

No branches or pull requests

4 participants