Skip to content

Raise PropertyChanged only if value has changed #433

@lucacivale

Description

@lucacivale

Is your feature request related to a problem? Please describe.

PropertyChanged is raised even if the property value has not changed.

This is a simple generated proxy

internal partial class Foo : Microsoft.OData.Client.BaseEntityType, System.ComponentModel.INotifyPropertyChanged
{
	public virtual string Name
	{
		get
		{
			return this._Name;
		}
		set
		{
			this.OnNameChanging(value);
			this._Name = value;
			this.OnNameChanged();
			this.OnPropertyChanged("Name");
		}
	}
	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
	private string _Name;
	partial void OnNameChanging(string value);
	partial void OnNameChanged();
}

Every time Foo.Name is set, the property change event is raised, even if the value hasn't actually changed. This may lead to SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties) sending properties that haven't actually changed

Describe the solution you'd like

Raise property changed only if value changed.

internal partial class Foo : Microsoft.OData.Client.BaseEntityType, System.ComponentModel.INotifyPropertyChanged
{
	public virtual string Name
	{
		get
		{
			return this._Name;
		}
		set
		{
			if (this.Name == value)
			{
				return;
			}
			this.OnNameChanging(value);
			this._Name = value;
			this.OnNameChanged();
			this.OnPropertyChanged("Name");
		}
	}
	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
	private string _Name;
	partial void OnNameChanging(string value);
	partial void OnNameChanged();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions