Open plamber opened 1 year ago
Thanks for raising this @plamber
I believe this API would be better placed in the BackingStore itself to change the suggestion to
bool hasChanges = user.BackingStore.HasChanges();
At the moment, I believe you can get away with an extension method close to this.
public static bool HasChanges(this IBackingStore store)
{
store.ReturnOnlyChangedValues = true;
return store. Enumerate().Any();
}
Hi @andrueastman, I ended up creating this extension method.
public static class GraphExtensions
{
public static bool HasChanges(this IBackingStore store)
{
bool originalValue = store.ReturnOnlyChangedValues;
store.ReturnOnlyChangedValues = true;
try
{
return store.Enumerate().Any();
}
finally
{
store.ReturnOnlyChangedValues = originalValue;
}
}
}
Thank you for your help.
Cheers
I would like to propose an enhancement to the Graph API .NET SDK that enables better handling of unchanged objects during patch and post operations. Currently, even if there are no changes in the object being updated, the patch operation is still executed. This feature request aims to provide a mechanism for identifying if an object has updated values and to prevent unnecessary execution of patch and post operations when no changes are present.
Maybe there is already a technique that can be used to accomplish this goal.
Describe the solution you'd like The suggested solution involves introducing two key features: the ability to identify if an object has updated values and the option to skip patch and post operations when no changes exist in the backing store. By implementing these features, developers can improve the efficiency and reduce unnecessary API calls in scenarios where object updates are conditional based on changes.
In the example above, the HasChanges() method is introduced to determine if the object contains any modified properties. This method compares the object's current state with the original values stored in the backing store to identify changes.
With this enhancement, developers gain more control over when to execute patch and post operations, preventing unnecessary API calls and improving performance in scenarios where updates are conditional.