在ASP.NET Core中,处理数据删除通常涉及到以下几个步骤:
ProductsController的控制器。using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    // ...
}
using System.Linq;
using Microsoft.EntityFrameworkCore;
// ...
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
    // ...
}
Product的实体类和一个名为ProductsContext的DbContext类。// ...
private readonly ProductsContext _context;
public ProductsController(ProductsContext context)
{
    _context = context;
}
// ...
// ...
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
    var product = await _context.Products.FindAsync(id);
    if (product == null)
    {
        return NotFound();
    }
    _context.Products.Remove(product);
    await _context.SaveChangesAsync();
    return NoContent();
}
现在,当客户端发送一个DELETE请求到/api/products/{id}时,Delete方法将从数据库中删除具有指定ID的产品。如果找不到该产品,将返回404 Not Found响应。如果成功删除产品,将返回204 No Content响应。