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

StackOverflow https://stackoverflow.com/questions/17519848

Domanda

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();
È stato utile?

Soluzione

This problem solved by adding PRIMARY KEY to the table.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top