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}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<IActionResult> DeleteTeam(int id)
|
public async Task<IActionResult> DeleteTeam(int id)
|
||||||
{
|
{
|
||||||
var team = await _context.Teams.FindAsync(id);
|
if (_context.Teams == null)
|
||||||
if (team == null)
|
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
await _context.Teams.Where(t => t.Id == id).ExecuteDeleteAsync();
|
||||||
_context.Teams.Remove(team);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user