Add example delete for coach.

This commit is contained in:
Kevin Matsubara 2025-04-05 23:26:53 +02:00
parent f58ce8f120
commit 86b2e60e8c

View File

@ -13,6 +13,17 @@ using var context = new DeadBallZoneLeagueDbContext();
// Rather than raise: "System.InvalidOperationException: Sequence contains no elements."
// var firstCoach = await context.Coaches.FirstOrDefaultAsync();
async Task DeleteCoach(int id)
{
var coach = await context.Coaches.FindAsync(id);
if (coach != null)
{
context.Remove(coach);
// context.Entry(coach).State = EntityState.Deleted;
await context.SaveChangesAsync();
}
}
async Task UpdateCoach()
{
var coach = await context.Coaches.FindAsync(1);