-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Description
Steps to reproduce
Following csproj and source code can be used to reproduce the issue.
ExecuteDeleteAsync send DELETE request to database even if cancellation already is requested by token.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
</ItemGroup>
</Project>public class Item
{
public DateTimeOffset Date { get; set; }
}
public class ItemsDbContext: DbContext
{
public ItemsDbContext(DbContextOptions options) : base(options) {}
public DbSet<Item> Items { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Item>().HasNoKey();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Items;Integrated Security=True");
}
}
var sp = new ServiceCollection()
.AddDbContext<ItemsDbContext>()
.BuildServiceProvider().CreateScope().ServiceProvider;
var ctx = sp.GetRequiredService<ItemsDbContext>();
using var cts = new CancellationTokenSource();
cts.Cancel();
count = await ctx.Items.Where(x => x.Date < DateTimeOffset.UtcNow).ExecuteDeleteAsync(cts.Token);
Console.WriteLine(count);Include provider and version information
EF Core version: 7.0.10
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Win10
IDE: Visual Studio 2022 17.7
dsgordeev