InvalidOperationException: The property is part of the object's key information and cannot be modified

你说的曾经没有我的故事 提交于 2019-12-24 14:42:06

问题


I'm getting this error when I try to change column value.

Here is how I got to this problem:

1) I was needed to add this bit column to an Existing table.

    ALTER TABLE BooksDB.dbo.Books
    ADD edited bit NOT NULL DEFAULT(0),

2) Updated my EF model in project.

3) Now when I try to change 'edited' property of entity object, I'm getting the error from Subject line.

Why is that?

EF object declaration:

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Boolean edited
    {
        get
        {
            return _edited;
        }
        set
        {
            if (_edited != value)
            {
                OneditedChanging(value);
                ReportPropertyChanging("edited");
                _edited = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("edited");
                OneditedChanged();
            }
        }
    }
    private global::System.Boolean _edited;
    partial void OneditedChanging(global::System.Boolean value);
    partial void OneditedChanged();

回答1:


This problem solved by adding PRIMARY KEY to the table.



来源:https://stackoverflow.com/questions/17519848/invalidoperationexception-the-property-is-part-of-the-objects-key-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!