Below code is written for updating "validTo" field for PositionWorkerAssignments entity in D365.
However no error is thrown, but data is not updated in the table/entity.
var query = Context.PositionWorkerAssignments.Where(s => s.PersonnelNumber == associate.PersonNumber) as DataServiceQuery<PositionWorkerAssignment>;
var response = await query.ExecuteAsync().ConfigureAwait(false);
var workerAssignment = response.FirstOrDefault();
if (workerAssignment != null)
{
var workerAssignmentCollection = new DataServiceCollection<PositionWorkerAssignment>(Context);
workerAssignmentCollection.Add(workerAssignment);
workerAssignment.ValidTo = DateTime.UtcNow.Date; //ending assignment
Context.UpdateObject(workerAssignment);
var saveResponse = await Context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties).ConfigureAwait(false);
}