我正在使用 LINQ to SQL 构建 Windows 窗体应用程序。我正在使用 dbml 文件中自动生成的代码。
Visual Studio 为我的表中的 CNPJ 属性生成了以下代码:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CNPJ", DbType="VarChar(20) NOT NULL", CanBeNull=false)]
public string CNPJ
{
get
{
return this._CNPJ;
}
set
{
if ((this._CNPJ != value))
{
this.OnCNPJChanging(value);
this.SendPropertyChanging();
this._CNPJ = value;
this.SendPropertyChanged("CNPJ");
this.OnCNPJChanged();
}
}
}
我想要的是这个:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CNPJ", DbType="VarChar(20) NOT NULL", CanBeNull=false)]
public string CNPJ
{
get
{
return APPLY_FORMAT(this._CNPJ);//Changed here
}
set
{
if ((this._CNPJ != value))
{
this.OnCNPJChanging(value);
this.SendPropertyChanging();
this._CNPJ = REMOVE_FORMAT(value); /// Changed here
this.SendPropertyChanged("CNPJ");
this.OnCNPJChanged();
}
}
}
但是当重新生成代码时,我会丢失这些更改。问题是:完成此行为的正确方法是什么(继承和覆盖,捕获更改事件,其他)?
如果您好奇,CNPJ 是巴西的商业识别号,由政府提供。