Optimise delete code with only 1 trip to database.
This commit is contained in:
parent
16ddb2d336
commit
2934b45018
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user