'OData Patch : Changed values not identified as changed

When my OData API recieves a PATCH, the updated values aren't recognized as being updated.

Class (Abbreviated):

public partial class Fiscal_Records_View
{
    public StipendRequested StipendOneRequested { get; set; } = StipendRequested.No;
    [Key]
    public Guid EmployeeId { get; set; }
    [Key]
    public Guid TrainingId { get; set; }
}

Enum referenced by class:

public enum StipendRequested
{
    [Description("Yes")]
    Yes = 1,

    [Description("No")]
    No = 2,

    [Description("Opted Out")]
    OptedOut = 3,

    [Description("Unknown")]
    Unknown = 4,
    }

Controller Method (PATCH):

[HttpPatch("Fiscal_Records_View({eid},{tid})")]
public async Task<IActionResult> UpdateFiscalRecords(Guid eid, Guid tid, [FromBody] Delta<Fiscal_Records_View> patch)

{
    if (!this.ModelState.IsValid)
    {
        return this.BadRequest(this.ModelState);
    }

    // DEBUG
    var instance = patch.GetInstance();
    var ChangedFields = patch.GetChangedPropertyNames();

    Fiscal_Records_View fiscalRecord = await this.itssMasterContext
   .Fiscal_Records_View
   .FirstOrDefaultAsync(t => t.EmployeeId == eid && t.TrainingId == tid);

   patch.Patch(fiscalRecord);
   await this.itssMasterContext.SaveChangesAsync();

   return this.Ok(fiscalRecord);
}

PATCH call made from PostMan:

URI: http://localhost:25584/odata/Fiscal_Records_View(4878A9BB-9501-4113-B20D-8D53616FDA13,B397B9BA-4C45-4065-A0A9-02EE474ED36E)

Body:
{
      "StipendOneRequested": 2
}

Controller values when call is made:

fiscalRecord : 
EmployeeId  {4878a9bb-9501-4113-b20d-8d53616fda13}
TrainingId  {b397b9ba-4c45-4065-a0a9-02ee474ed36e}
StipendOneRequested 1

instance:
EmployeeId  {00000000-0000-0000-0000-000000000000}
TrainingId  {00000000-0000-0000-0000-000000000000}
StipendOneRequested 2

ChangedFields:
Current NULL

So the controller is able to retrieve the record (fiscalRecord) from the context, and it appears to be recieving the correct delta (instance) where StipendOne has changed, but ChangedFields is NULL. As a result, the changes are not saved.

Any help greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source