I've faced the problem with using ExecuteDelete in the abstract generic class. Can someone explain in what cases ExecuteDelete and ExecuteUpdate cannot be used? Tagret framework is set to .NET 7
Here is how my code looks:
using Microsoft.EntityFrameworkCore;
namespace ProjectX.Common.Repositories;
public abstract class BaseRepository<T, V> : IRepository<T, V>
where T : Entity
where V : struct
{
protected readonly DbContext _context;
public BaseRepository(DbContext context)
{
_context = context;
}
public virtual async Task<bool> DeleteAsync(T entity, CancellationToken cancellationToken = default)
{
var deleted = await _context.Set<T>()
.Where(t => t.Id.Equals(entity.Id))
.ExecuteDeleteAsync(); // Here is the problem. This method cannot be found. Target Framework is .Net 7 and EF Core version is 7.0.7
return deleted > 0;
}
}
EF Core version: 7.0.7 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: NET 7.0 IDE: Visual Studio 2022 latest version