{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6155","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6155/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6155/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6155/events","html_url":"https://github.com/aspnet/EntityFramework/issues/6155","id":167370470,"number":6155,"title":"How to do data migrations inside an EF7 code first migration?","user":{"login":"shaulbehr","id":293329,"avatar_url":"https://avatars.githubusercontent.com/u/293329?v=3","gravatar_id":"","url":"https://api.github.com/users/shaulbehr","html_url":"https://github.com/shaulbehr","followers_url":"https://api.github.com/users/shaulbehr/followers","following_url":"https://api.github.com/users/shaulbehr/following{/other_user}","gists_url":"https://api.github.com/users/shaulbehr/gists{/gist_id}","starred_url":"https://api.github.com/users/shaulbehr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shaulbehr/subscriptions","organizations_url":"https://api.github.com/users/shaulbehr/orgs","repos_url":"https://api.github.com/users/shaulbehr/repos","events_url":"https://api.github.com/users/shaulbehr/events{/privacy}","received_events_url":"https://api.github.com/users/shaulbehr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-25T13:49:47Z","updated_at":"2016-07-27T05:18:33Z","closed_at":null,"body":"(Asked on [StackOverflow](http://stackoverflow.com/q/38568475/7850), but I'm hoping you guys will get me a more accurate answer, sooner...)\r\n\r\nIn my schema migration, I need to do a data migration to an external database. So I can't fall back on `migrationBuilder.Sql()`. What I need to do is run a query on the local database and insert the data returned into the external database. In other words, I want to do something like this:\r\n\r\n```\r\n// Obviously this is pseudo-code; these interfaces mostly don't exist\r\nprotected override void Up(MigrationBuilder migrationBuilder)\r\n{\r\n  var results = migrationBuilder.GetQueryResults(\"some query\");\r\n  using (var extDb = new ExternalDb())\r\n  {\r\n    foreach (var row in results) \r\n    {\r\n      InsertToExternalDb(row, extDb);\r\n    }\r\n  }\r\n}\r\n```\r\nBut I can't find any method on `MigrationBuilder` that returns rows from the current database, and I can't even find a way to get the connection string such that I could write a raw ADO query to the current database.\r\n\r\nAny other ideas how I could do this?"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/235489499","html_url":"https://github.com/aspnet/EntityFramework/issues/6155#issuecomment-235489499","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6155","id":235489499,"user":{"login":"rdefreitas","id":451585,"avatar_url":"https://avatars.githubusercontent.com/u/451585?v=3","gravatar_id":"","url":"https://api.github.com/users/rdefreitas","html_url":"https://github.com/rdefreitas","followers_url":"https://api.github.com/users/rdefreitas/followers","following_url":"https://api.github.com/users/rdefreitas/following{/other_user}","gists_url":"https://api.github.com/users/rdefreitas/gists{/gist_id}","starred_url":"https://api.github.com/users/rdefreitas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdefreitas/subscriptions","organizations_url":"https://api.github.com/users/rdefreitas/orgs","repos_url":"https://api.github.com/users/rdefreitas/repos","events_url":"https://api.github.com/users/rdefreitas/events{/privacy}","received_events_url":"https://api.github.com/users/rdefreitas/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T05:18:33Z","updated_at":"2016-07-27T05:18:33Z","body":"Currently, there is no way to return loaded entities inside of migrations, however, you can use the Sql method of MigrationBuilder inside your migrations.\r\n\r\n`migrationBuilder.Sql(\"UPDATE [dbo].[Foo] SET [Bar] = 1;\");`"}}
{"actor":{"display_login":"rdefreitas"}}