{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4898","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4898/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4898/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4898/events","html_url":"https://github.com/aspnet/EntityFramework/issues/4898","id":143224938,"number":4898,"title":"Support for multiple databases in the same model","user":{"login":"laskoviymishka","id":2754361,"avatar_url":"https://avatars.githubusercontent.com/u/2754361?v=3","gravatar_id":"","url":"https://api.github.com/users/laskoviymishka","html_url":"https://github.com/laskoviymishka","followers_url":"https://api.github.com/users/laskoviymishka/followers","following_url":"https://api.github.com/users/laskoviymishka/following{/other_user}","gists_url":"https://api.github.com/users/laskoviymishka/gists{/gist_id}","starred_url":"https://api.github.com/users/laskoviymishka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laskoviymishka/subscriptions","organizations_url":"https://api.github.com/users/laskoviymishka/orgs","repos_url":"https://api.github.com/users/laskoviymishka/repos","events_url":"https://api.github.com/users/laskoviymishka/events{/privacy}","received_events_url":"https://api.github.com/users/laskoviymishka/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/investigation-needed","name":"investigation-needed","color":"0052cc"}],"state":"open","locked":false,"assignee":{"login":"anpete","id":1210944,"avatar_url":"https://avatars.githubusercontent.com/u/1210944?v=3","gravatar_id":"","url":"https://api.github.com/users/anpete","html_url":"https://github.com/anpete","followers_url":"https://api.github.com/users/anpete/followers","following_url":"https://api.github.com/users/anpete/following{/other_user}","gists_url":"https://api.github.com/users/anpete/gists{/gist_id}","starred_url":"https://api.github.com/users/anpete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anpete/subscriptions","organizations_url":"https://api.github.com/users/anpete/orgs","repos_url":"https://api.github.com/users/anpete/repos","events_url":"https://api.github.com/users/anpete/events{/privacy}","received_events_url":"https://api.github.com/users/anpete/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/19","html_url":"https://github.com/aspnet/EntityFramework/milestones/1.1.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/19/labels","id":1748298,"number":19,"title":"1.1.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":145,"closed_issues":21,"state":"open","created_at":"2016-05-04T18:23:47Z","updated_at":"2016-06-17T21:20:18Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2016-03-24T11:43:56Z","updated_at":"2016-06-18T09:21:00Z","closed_at":null,"body":"Issue based on  #4019 and PR #4672\r\nIt nice to have a feature to access multiple database from same model context.\r\nThis feature pretty massive. We need to modify following areas:\r\n1) Add database property to relational type annotations and follow this property from explicit mapping to default query sql generator (to create proper table alias including database name)\r\n2) Enhance data model with new field for catalogue name\r\n3) Implement sql generator and model validator for code first migrations from model with multiple databases (it means we should modify all generators and migration operators)\r\n4) Implement additional annotations to support attribute database generation, not only explicit\r\n\r\nThere are still some open design questions that needs to be resolved:\r\n1) There is no database/catalog propery in TableAttribute\r\n\r\nSo we could not implement data annotation mapping to different database. There is a possible solution by introducing additional attribute for this need (like DatabaseAttribute) with single proprte Name. In this case usage could be fairly simple\r\n\r\n```\r\n[Database(\"Pink\")]\r\n[Table(\"Unicorns\", Schema=\"Fluffy\")]\r\nclass DifferentDatabaseItem{ }\r\n```\r\n\r\nAlso there is should be modelBuilder interface to setup database catalogue manually. Something like this:\r\n```\r\n modelBuilder.Entity<MappingQueryTestBase.DifferentDatabaseItem>(e =>\r\n            {\r\n                e.Metadata.Relational().TableName = \"Unicorns\";\r\n                e.Metadata.Relational().Schema = \"Fluffy\";\r\n                e.Metadata.Relational().Database = \"Pink\";\r\n            });\r\n```\r\n\r\nFor such models we should generate additional catalogue prefix for ```FROM``` and ```JOIN``` statements.\r\n\r\n2) There is issue with navigation property building. We could easily generate proper join statement cross catalogues, but there is no proper way to add foreign key for such properties. \r\nThere is couple possible solutions:\r\n- Forbid adding navigation properties between databases. This aproach is not really healthy. If we implement this - there is no particullar reason to keep multiple catalogues in single model context.\r\n- Allow adding navigation properties, but enhance migration to prevent generating foreighn key operations for this properties. In this case we could work with our entities without any penalties, but from data storage perspective we will not have any \"real\" foreighn keys between them.\r\n\r\n3) There is open question regards to should this be a relational concept, or specific to SQL Server. As far as i know this behaivior supported in MySql and Oracle (if placed on same server). Not sure for postgre SQL and sql lite.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/226931963","html_url":"https://github.com/aspnet/EntityFramework/issues/4898#issuecomment-226931963","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4898","id":226931963,"user":{"login":"GSPP","id":12032350,"avatar_url":"https://avatars.githubusercontent.com/u/12032350?v=3","gravatar_id":"","url":"https://api.github.com/users/GSPP","html_url":"https://github.com/GSPP","followers_url":"https://api.github.com/users/GSPP/followers","following_url":"https://api.github.com/users/GSPP/following{/other_user}","gists_url":"https://api.github.com/users/GSPP/gists{/gist_id}","starred_url":"https://api.github.com/users/GSPP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GSPP/subscriptions","organizations_url":"https://api.github.com/users/GSPP/orgs","repos_url":"https://api.github.com/users/GSPP/repos","events_url":"https://api.github.com/users/GSPP/events{/privacy}","received_events_url":"https://api.github.com/users/GSPP/received_events","type":"User","site_admin":false},"created_at":"2016-06-18T09:21:00Z","updated_at":"2016-06-18T09:21:00Z","body":"@tillig this is absolutely part of this issue (at least the part that's by me and was merged into this one)."}}
{"actor":{"display_login":"GSPP"}}