如果从本地数据库中提取LINQ-to-SQL类,则不会实现INotifyPropertyChanging和INotifyPropertyChanged

Fec*_*ore 5 c# linq interface linq-to-sql

我在LINQ-to-SQL类中修改了我的数据源(通过旧的删除并在方法中向后拖动),并且惊讶地看到生成的类(MyDb.designer.cs)中不再实现INotifyPropertyChanging和INotifyPropertyChanged接口.

各个领域的方法看起来像这样......

[Column(Storage="_Size", DbType="NVarChar(100)")]
public string Size
{
    get
    {
        return this._Size;
    }
    set
    {
        if ((this._Size != value))
        {
            this.OnSizeChanging(value);
            this.SendPropertyChanging();
            this._Size = value;
            this.SendPropertyChanged("Size");
            this.OnSizeChanged();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

看起来像这样......

[Column(Storage="_Size", DbType="NVarChar(100)")]
public string Size
{
    get
    {
        return this._Size;
    }
    set
    {
        if ((this._Size != value))
        {
            this._Size = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有关为什么会发生这种情况以及它将如何影响我的应用程序的任

Mar*_*tój 15

确保您的表具有主键.


Ada*_*dam 5

检查以确保未设置ObjectTrackingEnabled = false;或未在设计器表面上将其关闭.