Optimise delete code with only 1 trip to database.

This commit is contained in:
Kevin Matsubara 2025-04-14 11:57:59 +02:00
parent 16ddb2d336
commit 2934b45018

View File

@ -88,15 +88,11 @@ namespace EntityFrameworkCore.API.Controllers
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteTeam(int id)
{
var team = await _context.Teams.FindAsync(id);
if (team == null)
if (_context.Teams == null)
{
return NotFound();
}
_context.Teams.Remove(team);
await _context.SaveChangesAsync();
await _context.Teams.Where(t => t.Id == id).ExecuteDeleteAsync();
return NoContent();
}