我遇到的问题是,没有为所有属性引发生成的Ria Services实体的PropertyChanged事件 .
当我查看生成的代码(客户端)时,我可以看到我的实体派生自实现INotifyPropertyChanged的Entity对象 . 我还可以看到一些属性,比如Id属性,正在引发PropertyChanged事件,但有些属性不是 .
我没有使用任何T4模板,因此使用了默认值 .
所以,我的问题是:
是否有可以设置的选项/属性,以便为生成的客户端实体的任何属性引发PropertyChanged事件?
任何帮助,将不胜感激 .
编辑:
这是一个属性的示例,在自动生成的 client-side 文件中, doesn't 引发了PropertyChanged事件:
[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();
}
}
}
这就是模型_1554796中定义的内容:
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String FirstName
{
get
{
return _FirstName;
}
set
{
OnFirstNameChanging(value);
ReportPropertyChanging("FirstName");
_FirstName = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("FirstName");
OnFirstNameChanged();
}
}
这是一个属性的示例,在自动生成的 client-side 文件中, does 引发了PropertyChanged事件:
[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();
}
}
}
这就是模型_1554801中定义的内容:
[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();
}
}
}
1 回答
PropertyChanged 事件封装在 RaiseDataMemberChanged ()中 . 您可以使用任何Decompiler(.NET Reflector等)进行检查 .
RaiseDataMemberChanged和RaiseDataMemberChanging方法用于通知框架有关更改跟踪和状态转换的更改 .
这两个属性是不同的,导致Id属性用Key-Attribute修饰 . 我认为具有此属性的属性由于与其他实体的关联以及不同的自动生成实现而得到特殊处理,因为不需要跟踪更改或转换 .
所以在你的情况下,我认为还有另一个问题,为什么你的PropertyChanged事件(也许)没有被解雇 .