{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1655","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1655/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1655/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1655/events","html_url":"https://github.com/aspnet/EntityFramework/issues/1655","id":58243452,"number":1655,"title":"InvalidCastException when syncing primary key for MySql","user":{"login":"bartdevriendt","id":781706,"avatar_url":"https://avatars.githubusercontent.com/u/781706?v=3","gravatar_id":"","url":"https://api.github.com/users/bartdevriendt","html_url":"https://github.com/bartdevriendt","followers_url":"https://api.github.com/users/bartdevriendt/followers","following_url":"https://api.github.com/users/bartdevriendt/following{/other_user}","gists_url":"https://api.github.com/users/bartdevriendt/gists{/gist_id}","starred_url":"https://api.github.com/users/bartdevriendt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartdevriendt/subscriptions","organizations_url":"https://api.github.com/users/bartdevriendt/orgs","repos_url":"https://api.github.com/users/bartdevriendt/repos","events_url":"https://api.github.com/users/bartdevriendt/events{/privacy}","received_events_url":"https://api.github.com/users/bartdevriendt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/pri0","name":"pri0","color":"e11d21"}],"state":"closed","locked":false,"assignee":{"login":"ajcvickers","id":1430078,"avatar_url":"https://avatars.githubusercontent.com/u/1430078?v=3","gravatar_id":"","url":"https://api.github.com/users/ajcvickers","html_url":"https://github.com/ajcvickers","followers_url":"https://api.github.com/users/ajcvickers/followers","following_url":"https://api.github.com/users/ajcvickers/following{/other_user}","gists_url":"https://api.github.com/users/ajcvickers/gists{/gist_id}","starred_url":"https://api.github.com/users/ajcvickers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajcvickers/subscriptions","organizations_url":"https://api.github.com/users/ajcvickers/orgs","repos_url":"https://api.github.com/users/ajcvickers/repos","events_url":"https://api.github.com/users/ajcvickers/events{/privacy}","received_events_url":"https://api.github.com/users/ajcvickers/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7","html_url":"https://github.com/aspnet/EntityFramework/milestones/7.0.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7/labels","id":666128,"number":7,"title":"7.0.0","description":"","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":172,"closed_issues":155,"state":"open","created_at":"2014-05-21T19:25:32Z","updated_at":"2015-05-04T20:14:44Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-02-19T17:50:45Z","updated_at":"2015-05-04T20:14:44Z","closed_at":"2015-05-04T20:14:44Z","body":"I'm working on a MySql provider for EF and I'm having trouble syncing the primary key of model objects with the database.\r\n\r\nI tracked down the problem to this:\r\n\r\nMicrosoft.Data.Entity.Relational.Update.ModificationCommand.PropagateResults uses reader.ReadValue<object> to read the inserted value from the database.  In MySql the LAST_INSERT_ID() function returns a 64-bit int which is converted to ulong in c#.  \r\n\r\nMicrosoft.Data.Entity.ChangeTracking.Internal.SimpleEntityKeyFactory.Create further on tries to unbox the retrieved value (ulong) to the typedvalue (int) which generates an InvalidCastException on this line:\r\n\r\nvar typedValue = (TKey)value;\r\n\r\nOne proposed solution would be to change this to:\r\n\r\nvar typedValue = Convert.ChangeType(value, typeof(TKey));\r\n\r\nWould there be a better way ?  "}}