WCF Ria Services entities and INotifyPropertyChanged
I am having an issue where the PropertyChanged event from the generated Ria Services entities is not raised for all the properties.
When I look at the generated code (client-side), I can see that my entities are deriving from the Entity object which implements INotifyPropertyChanged. I can also see that some properties, like the Id property, is raising the PropertyChanged event but some are not.
I did not use any T4 templates so the default were used.
So, my question is:
Is there an option/attribute that I can set so that the PropertyChanged event be raised for any properties of the generated client-side entities?
Any help would be appreciated.
EDIT:
Here's an example of a property, in the auto-generated client-side file, which doesn't raise the PropertyChanged event:
[DataMember()]
[Required()]
[StringLength(50)]
public string FirstName
{
get
{
return this._firstName;
}
set
{
if ((this._firstName != value))
{
this.OnFirstNameChanging(value);
this.RaiseDataMemberChanging("FirstName");
this.ValidateProperty("FirstName", value);
this._firstName = value;
this.RaiseDataMemberChanged("FirstName");
this.OnFirstNameChanged();
}
}
}
And this is what was defined in the model server-side:
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String FirstName
{
get
{
return _FirstName;
}
set
{
OnFirstNameChanging(value);
ReportPropertyChanging("FirstName");
_FirstName = Structura开发者_Python百科lObject.SetValidValue(value, false);
ReportPropertyChanged("FirstName");
OnFirstNameChanged();
}
}
Here's an example of a property, in the auto-generated client-side file, which does raise the PropertyChanged event:
[DataMember()]
[Editable(false, AllowInitialValue=true)]
[Key()]
[RoundtripOriginal()]
public Guid Id
{
get
{
return this._id;
}
set
{
if ((this._id != value))
{
this.OnIdChanging(value);
this.ValidateProperty("Id", value);
this._id = value;
this.RaisePropertyChanged("Id");
this.OnIdChanged();
}
}
}
And this is what was defined in the model server-side:
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Guid Id
{
get
{
return _Id;
}
set
{
if (_Id != value)
{
OnIdChanging(value);
ReportPropertyChanging("Id");
_Id = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Id");
OnIdChanged();
}
}
}
The PropertyChanged event is encapsulated in the RaiseDataMemberChanged(). You can check this with any Decompiler (.NET Reflector, etc.).
The RaiseDataMemberChanged and RaiseDataMemberChanging methods are used to notify the framework about changes for change tracking and state transitions.
These two properties are diffrent, cause the Id property is decorated with the Key-Attribute. I think properties with this attribute get special handling, due to associations with other entities, and a diffrent auto-generated implementation, cause there is not need to track changes or transistions on change.
So in your case, i think there is another problem, why your PropertyChanged event is (maybe) not fired.
精彩评论