查看您的模型.Designer.cs
文件。你会看到这样的东西:
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String MobilePhoneNo
{
get
{
return _MobilePhoneNo;
}
set
{
OnMobilePhoneNoChanging(value);
ReportPropertyChanging("MobilePhoneNo");
_MobilePhoneNo = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("MobilePhoneNo");
OnMobilePhoneNoChanged();
}
}
private global::System.String _MobilePhoneNo;
partial void OnMobilePhoneNoChanging(global::System.String value);
partial void OnMobilePhoneNoChanged();
Notice that as well as the partial Changing
and Changed
methods you already know about, there's a backing field. Because your code is in a partial piece of the class, you have access to all members, including the private ones. So you can implement the partial Changed
method, and directly alter _MobilePhoneNo
:
partial void OnMobilePhoneNoChanged()
{
if (_MobilePhoneNo != null)
{
_MobilePhoneNo = ATG_COModel_Common.FormatPhoneNumber(_MobilePhoneNo);
}
}
which is what you want.