I got this PATCH endpoint in my C# ASP.NET Core Web API that uses Entity Framework to store my games:
[HttpPatch]
public async Task<ActionResult<Game>> GetGame(long id) {
var game = await _context.Games.FindAsync(id);
if (game == null) {
return NotFound();
}
game.State.Map = MapUtils.generateMap();
_context.Entry(game).State = EntityState.Modified;
try {
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException) {
if (!GameUtils.GameExists(_context, id)) {
return NotFound();
}
else {
throw;
}
}
return game;
}
When this function is called I get the updated game with Map being set to a List of rows and columns as the response. But then when I use my GET endpoint to retrieve the updated game at a later stage, map is null which means that my entry couldn't have been updated when calling the PATCH.
Here is the GET for retrieving a single game:
[HttpGet("{id}")]
public async Task<ActionResult<Game>> GetGame(long id) {
var game = await _context.Games.FindAsync(id);
if (game == null) {
return NotFound();
}
return game;
}
I've tried some solutions from this question but I get the same result.
What am I doing wrong?