{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3123","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3123/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3123/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3123/events","html_url":"https://github.com/aspnet/EntityFramework/issues/3123","id":106229409,"number":3123,"title":"Raising PropertyChanged notification on entity key throws exception \"The property 'EntityId' on entity type 'Entity' is part of a key and so cannot be modified or marked as modified.\"","user":{"login":"sgmon","id":14262633,"avatar_url":"https://avatars.githubusercontent.com/u/14262633?v=3","gravatar_id":"","url":"https://api.github.com/users/sgmon","html_url":"https://github.com/sgmon","followers_url":"https://api.github.com/users/sgmon/followers","following_url":"https://api.github.com/users/sgmon/following{/other_user}","gists_url":"https://api.github.com/users/sgmon/gists{/gist_id}","starred_url":"https://api.github.com/users/sgmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgmon/subscriptions","organizations_url":"https://api.github.com/users/sgmon/orgs","repos_url":"https://api.github.com/users/sgmon/repos","events_url":"https://api.github.com/users/sgmon/events{/privacy}","received_events_url":"https://api.github.com/users/sgmon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"divega","id":1253414,"avatar_url":"https://avatars.githubusercontent.com/u/1253414?v=3","gravatar_id":"","url":"https://api.github.com/users/divega","html_url":"https://github.com/divega","followers_url":"https://api.github.com/users/divega/followers","following_url":"https://api.github.com/users/divega/following{/other_user}","gists_url":"https://api.github.com/users/divega/gists{/gist_id}","starred_url":"https://api.github.com/users/divega/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divega/subscriptions","organizations_url":"https://api.github.com/users/divega/orgs","repos_url":"https://api.github.com/users/divega/repos","events_url":"https://api.github.com/users/divega/events{/privacy}","received_events_url":"https://api.github.com/users/divega/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/9","html_url":"https://github.com/aspnet/EntityFramework/milestones/Discussions","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/9/labels","id":692755,"number":9,"title":"Discussions","description":"<!--\r\n@huboard:{\"order\":101}\r\n-->","creator":{"login":"rowanmiller","id":4741851,"avatar_url":"https://avatars.githubusercontent.com/u/4741851?v=3","gravatar_id":"","url":"https://api.github.com/users/rowanmiller","html_url":"https://github.com/rowanmiller","followers_url":"https://api.github.com/users/rowanmiller/followers","following_url":"https://api.github.com/users/rowanmiller/following{/other_user}","gists_url":"https://api.github.com/users/rowanmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/rowanmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowanmiller/subscriptions","organizations_url":"https://api.github.com/users/rowanmiller/orgs","repos_url":"https://api.github.com/users/rowanmiller/repos","events_url":"https://api.github.com/users/rowanmiller/events{/privacy}","received_events_url":"https://api.github.com/users/rowanmiller/received_events","type":"User","site_admin":false},"open_issues":36,"closed_issues":50,"state":"open","created_at":"2014-06-16T19:38:35Z","updated_at":"2015-09-23T19:16:49Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2015-09-13T17:37:40Z","updated_at":"2015-09-23T22:15:18Z","closed_at":null,"body":"### Environment\r\nUniversalWindowsApp running on Windows 10.\r\nVisual Studio 2015\r\nEntity Framework 7 beta 6\r\nSQLite database\r\n{\r\n  \"dependencies\": {\r\n    \"EntityFramework.Commands\": \"7.0.0-beta6\",\r\n    \"EntityFramework.Sqlite\": \"7.0.0-beta6\",\r\n    \"Microsoft.ApplicationInsights\": \"1.0.0\",\r\n    \"Microsoft.ApplicationInsights.PersistenceChannel\": \"1.0.0\",\r\n    \"Microsoft.ApplicationInsights.WindowsApps\": \"1.0.0\",\r\n    \"Microsoft.CodeAnalysis.CSharp\": \"1.0.0\",\r\n    \"Microsoft.NETCore.UniversalWindowsPlatform\": \"5.0.0\",\r\n    \"Microsoft.NETNative.Analyzer\": \"1.0.0\",\r\n    \"Prism.Mvvm\": \"1.1.1\"\r\n  },\r\n  \"frameworks\": {\r\n    \"uap10.0\": {}\r\n  },\r\n\r\n\r\n### Create an entity similar to this, and raise Property changed event for entities primary key as below\r\n\r\n    public class Entity : INotifyPropertyChanged\r\n    {\r\n        private int entityId;\r\n        public int EntityId\r\n        {\r\n            get { return entityId; }\r\n            set\r\n            {\r\n                // For brevity sake checking if value has really changed, and if it really not on the UI thread removed.\r\n                            var ignored = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(\r\n                                Windows.UI.Core.CoreDispatcherPriority.Normal,\r\n                                () =>\r\n                                {\r\n                                    PropertyChanged(this, new PropertyChangedEventArgs(nameof(AccountId)));\r\n                                    // Exception raised here. Note: set is being called by EntityFramework and not by user code; though the above statement is occurring on the UI thread and not directly by Entity Framework.\r\n                                });\r\n            }\r\n        }\r\n   }\r\n\r\n### Steps to reproduce\r\n1. Create object context.\r\n2. Create an instance of entity.\r\n3. Save changes on object context.\r\n\r\n### Call stack of exception looks like\r\nException thrown as \"The property 'EntityId' on entity type 'Entity' is part of a key and so cannot be modified or marked as modified.\"\r\n\r\n   at Microsoft.Data.Entity.ChangeTracking.Internal.InternalEntityEntry.SetPropertyModified(IProperty property, Boolean isModified)\r\n   at Microsoft.Data.Entity.ChangeTracking.Internal.ChangeDetector.PropertyChanged(InternalEntityEntry entry, IPropertyBase propertyBase)\r\n   at Microsoft.Data.Entity.ChangeTracking.Internal.InternalEntityEntryNotifier.<>c__DisplayClass12_0.<PropertyChanged>b__0(IPropertyListener l)\r\n   at Microsoft.Data.Entity.ChangeTracking.Internal.InternalEntityEntryNotifier.Dispatch(Action`1 action)\r\n   at Microsoft.Data.Entity.ChangeTracking.Internal.InternalEntityEntryNotifier.PropertyChanged(InternalEntityEntry entry, IPropertyBase property)\r\n   at Microsoft.Data.Entity.ChangeTracking.Internal.InternalEntityEntrySubscriber.<>c__DisplayClass2_0.<SnapshotAndSubscribe>b__2(Object s, PropertyChangedEventArgs e)\r\n   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)\r\n   at MyNamespace.Entity.<set_EntityId>b__3_0()\r\n\r\n### Workaround\r\nDo not raise property changed events just for primary key from user code. When we use code generators this becomes an issue to not raise events just for primary keys.\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/142746411","html_url":"https://github.com/aspnet/EntityFramework/issues/3123#issuecomment-142746411","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3123","id":142746411,"user":{"login":"divega","id":1253414,"avatar_url":"https://avatars.githubusercontent.com/u/1253414?v=3","gravatar_id":"","url":"https://api.github.com/users/divega","html_url":"https://github.com/divega","followers_url":"https://api.github.com/users/divega/followers","following_url":"https://api.github.com/users/divega/following{/other_user}","gists_url":"https://api.github.com/users/divega/gists{/gist_id}","starred_url":"https://api.github.com/users/divega/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divega/subscriptions","organizations_url":"https://api.github.com/users/divega/orgs","repos_url":"https://api.github.com/users/divega/repos","events_url":"https://api.github.com/users/divega/events{/privacy}","received_events_url":"https://api.github.com/users/divega/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T22:15:18Z","updated_at":"2015-09-23T22:15:18Z","body":"@sgmon Could you provide some information about the pattern you are using in your implementation of `INotifyPropertyChanged`? Did you need to do this to have the UI work correctly with notifications in UWAs? Is this a pattern you found somewhere? Where? How common is this type of implementation?\r\n\r\nTo give you some background: EF needs the notification to happen immediately and in the same thread as the change, otherwise it won't work. We cannot think of any way we can support notifications being dispatched in a different thread in the way your code does it, so at this point we are mulling whether we are going to need a flag somewhere in our API to force change detection to compare property values against snapshots even if the `INotify*` interfaces are implemented (in case they are implemented in an unsupported way)."}}