LINQ-to-SQL类没有实现INotifyPropertyChanging&如果从本地数据库中提取INotifyPropertyChanged

时间:2010-05-13 20:39:30

标签: c# linq linq-to-sql interface

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

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

[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();
        }
    }
}

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

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

关于为什么会发生这种情况以及它将如何影响我的申请的任何想法?

4 个答案:

答案 0 :(得分:14)

确保您的表有主键。

答案 1 :(得分:5)

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

答案 2 :(得分:1)

添加主键可以解决问题。

答案 3 :(得分:0)

拖放后你是否在设计师中改变了一些东西? IIRC,有一个跟踪的财产或其他一些。