0
votes

I have a net core 6 web api endpoint like this (shortened for brevity):

[HttpPut("{id}")]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<ActionResult<ArbitrationCase>> UpdateCaseAsync(int id, [FromBody] ArbitrationCase arbCase)
{

     var orig = await _context.ArbitrationCases
                        .Include(c => c.Arbitrators)
                        .Include(c => c.CPTCodes)
                        .Include(d => d.Notes)
                        .Include(d => d.OfferHistory)
                        .FirstOrDefaultAsync(d => d.Id == arbCase.Id);

     _context.Entry(orig).CurrentValues.SetValues(arbCase);

     // inclusion of the next line will prevent the service from returning a value
     // it will return an Ok - 200 response but the response will be empty
     // var payor = await _context.Payors.FindAsync(arbCase.PayorId.Value);

     await _context.SaveChangesAsync();
     return Ok(orig);
}

As mentioned in the code block above, if I uncomment the line that that fetches payor, the service stops returning the "orig" object. Is there some sort of single-use limit on the _context that I am violating? This seems broken to me.

[Edit] Just to be clear, the Payors.FindAsync(...) method does not generate an error. It will either return a value or null if the Payor record does not exist. The return Ok(orig) line is always hit.