METHOD

EntityFrameworkQueryableExtensions.ExecuteDelete

Executes a translated deletion immediately and reports affected rows, without synchronizing tracked objects or using SaveChanges. Add explicit concurrency predicates when needed; group multiple commands in a transaction if atomicity is required. Provider and query shape determine support.

Formal Syntax & Structure

csharp syntaxcsharp
context.Items.Where(x => x.Id == id).ExecuteDelete()

Working Example

Example Snippetcsharp
using System;using System.Data;using System.Data.Common;using Microsoft.EntityFrameworkCore;// Partial snippet: existing relational context and known lab ID.int affected=context.Items.Where(x=>x.Id==id).ExecuteDelete();
C# & .NET Reference