{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/24780507","id":24780507,"diff_hunk":"@@ -0,0 +1,277 @@\n+﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+using System.Collections.Generic;\n+using System.Globalization;\n+using System.Linq;\n+using Microsoft.Data.Entity.Metadata;\n+using Microsoft.Data.Entity.Relational.Design.CodeGeneration;\n+using Microsoft.Data.Entity.Relational.Design.ReverseEngineering;\n+using Microsoft.Data.Entity.SqlServer.Metadata;\n+using Microsoft.Data.Entity.Utilities;\n+\n+namespace Microsoft.Data.Entity.SqlServer.Design.ReverseEngineering\n+{\n+    public class SqlServerDbContextCodeGeneratorContext : DbContextCodeGenerator\n+    {\n+        public SqlServerDbContextCodeGeneratorContext(\n+            ReverseEngineeringGenerator generator,\n+            IModel model, string namespaceName,\n+            string className, string connectionString)\n+            : base(generator, model, namespaceName, className, connectionString)\n+        {\n+        }\n+\n+        public override IEnumerable<IEntityType> OrderedEntityTypes()\n+        {\n+            // do not configure EntityTypes for which we had an error when generating\n+            return Model.EntityTypes.OrderBy(e => e.Name)\n+                .Where(e => ((EntityType)e).TryGetAnnotation(SqlServerMetadataModelProvider.AnnotationNameEntityTypeError) == null);\n+        }\n+\n+        public override void GenerateNavigationsConfiguration(IndentedStringBuilder sb, IEntityType entityType)\n+        {\n+            foreach (var foreignKey in entityType.ForeignKeys.Cast<ForeignKey>())\n+            {\n+                var dependentEndNavigationPropertyName = foreignKey\n+                    .GetAnnotation(SqlServerMetadataModelProvider.AnnotationNameDependentEndNavPropName);\n+                var principalEndNavigationPropertyName = foreignKey\n+                    .TryGetAnnotation(SqlServerMetadataModelProvider.AnnotationNamePrincipalEndNavPropName);\n+                sb.AppendLine();\n+                sb.Append(\"entity.\");\n+                sb.Append(\"HasOne\");\n+                sb.Append(\"<\");\n+                sb.Append(foreignKey.ReferencedEntityType.Name);\n+                sb.Append(\">( d => d.\");\n+                sb.Append(dependentEndNavigationPropertyName.Value);\n+                sb.Append(\" )\");\n+\n+                if (principalEndNavigationPropertyName != null)\n+                {\n+                    if (((IForeignKey)foreignKey).IsUnique)\n+                    {\n+                        sb.Append(\".WithOne( \");\n+                    }\n+                    else\n+                    {\n+                        sb.Append(\".WithMany( \");\n+                    }\n+                    sb.Append(\"p => p.\");\n+                    sb.Append(principalEndNavigationPropertyName.Value);\n+                    sb.Append(\" )\");\n+                }\n+\n+                sb.Append(\";\");\n+            }\n+        }\n+\n+        public override void GenerateEntityFacetsConfiguration(IndentedStringBuilder sb, IEntityType entityType)\n+        {\n+            var nonForSqlServerEntityFacetsConfiguration = GenerateNonForSqlServerEntityFacetsConfiguration(entityType);\n+            var forSqlServerEntityFacetsConfiguration = GenerateForSqlServerEntityFacetsConfiguration(entityType);\n+\n+            if (nonForSqlServerEntityFacetsConfiguration.Count > 0\n+                || forSqlServerEntityFacetsConfiguration.Count > 0)\n+            {\n+                foreach (var facetConfig in nonForSqlServerEntityFacetsConfiguration)\n+                {\n+                    sb.AppendLine();\n+                    sb.Append(facetConfig);\n+                }\n+\n+                if (forSqlServerEntityFacetsConfiguration.Count > 0)\n+                {\n+                    sb.AppendLine();\n+                    sb.Append(\"entity.ForSqlServer()\");\n+                    using (sb.Indent())\n+                    {\n+                        foreach (var facetConfig in forSqlServerEntityFacetsConfiguration)\n+                        {\n+                            sb.AppendLine();\n+                            sb.Append(facetConfig);\n+                        }\n+                    }\n+                }\n+                sb.Append(\";\");\n+            }\n+        }\n+\n+        public virtual List<string> GenerateNonForSqlServerEntityFacetsConfiguration(IEntityType entityType)\n+        {\n+            return new List<string>();\n+        }\n+\n+        public virtual List<string> GenerateForSqlServerEntityFacetsConfiguration(IEntityType entityType)\n+        {\n+            var facetsConfig = new List<string>();\n+            var tableNameFacetConfig = GenerateTableNameFacetConfiguration(entityType);\n+            if (tableNameFacetConfig != null)\n+            {\n+                facetsConfig.Add(tableNameFacetConfig);\n+            }\n+\n+            return facetsConfig;\n+        }\n+\n+        public virtual string GenerateTableNameFacetConfiguration(IEntityType entityType)\n+        {\n+            if (\"dbo\" != entityType.SqlServer().Schema)","path":"src/EntityFramework.SqlServer.Design/ReverseEngineering/SqlServerDbContextCodeGeneratorContext.cs","position":118,"original_position":118,"commit_id":"4a17ebaa4120613e6f6f0e08b1ce8a5cf9a0c57a","original_commit_id":"4a17ebaa4120613e6f6f0e08b1ce8a5cf9a0c57a","user":{"login":"bricelam","id":1226749,"avatar_url":"https://avatars.githubusercontent.com/u/1226749?v=3","gravatar_id":"","url":"https://api.github.com/users/bricelam","html_url":"https://github.com/bricelam","followers_url":"https://api.github.com/users/bricelam/followers","following_url":"https://api.github.com/users/bricelam/following{/other_user}","gists_url":"https://api.github.com/users/bricelam/gists{/gist_id}","starred_url":"https://api.github.com/users/bricelam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bricelam/subscriptions","organizations_url":"https://api.github.com/users/bricelam/orgs","repos_url":"https://api.github.com/users/bricelam/repos","events_url":"https://api.github.com/users/bricelam/events{/privacy}","received_events_url":"https://api.github.com/users/bricelam/received_events","type":"User","site_admin":false},"body":"This is a little different than a convention. If you don't specify a schema, we don't pass one to the database and it decides what to do. This is different from EF6 where we always specified a schema and dbo happened to be EF's default.","created_at":"2015-02-16T22:36:14Z","updated_at":"2015-02-16T22:36:14Z","html_url":"https://github.com/aspnet/EntityFramework/pull/1601#discussion_r24780507","pull_request_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601","_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/24780507"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/1601#discussion_r24780507"},"pull_request":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601","id":29153304,"html_url":"https://github.com/aspnet/EntityFramework/pull/1601","diff_url":"https://github.com/aspnet/EntityFramework/pull/1601.diff","patch_url":"https://github.com/aspnet/EntityFramework/pull/1601.patch","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1601","number":1601,"state":"open","locked":false,"title":"Initial checkin for Reverse Engineering","user":{"login":"lajones","id":1915927,"avatar_url":"https://avatars.githubusercontent.com/u/1915927?v=3","gravatar_id":"","url":"https://api.github.com/users/lajones","html_url":"https://github.com/lajones","followers_url":"https://api.github.com/users/lajones/followers","following_url":"https://api.github.com/users/lajones/following{/other_user}","gists_url":"https://api.github.com/users/lajones/gists{/gist_id}","starred_url":"https://api.github.com/users/lajones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lajones/subscriptions","organizations_url":"https://api.github.com/users/lajones/orgs","repos_url":"https://api.github.com/users/lajones/repos","events_url":"https://api.github.com/users/lajones/events{/privacy}","received_events_url":"https://api.github.com/users/lajones/received_events","type":"User","site_admin":false},"body":"This is the initial check in for Reverse Engineering on which we'll iterate. See issue #830.\r\n\r\nFeatures include: \r\nProduces DbContext and EntityType POCO classes in current project.\r\nOutputs class, properties and navigations in EntityType classes and class, DbSet's and OnConfiguring() and OnModelCreating() configuration for DbContext class.\r\nWorks from command line like Migrations.\r\nOutputs warnings to command line through a Logger.\r\nCode has been pulled out into separate EntityFramework.Relational.Design and EntityFramework.SqlServer.Design projects.\r\nSupports most SQL Server types (see SqlServerTypeMapping for complete list).\r\nOutput fluent API for EntityType defines the schema and table name (if necessary) and the primary key.\r\nOutput fluent API for properties outputs appropriate fluent API (as necessary) to determine column name and type, including precision and scale; Identity and StoreComputed columns; and MaxLength.\r\nOutput fluent API to support 1:N and 1:1 style navigations, plus self-referencing navigations.\r\nOutputs comments in the generated code if it is unable to generate a) EntityType, b) Navigations.\r\n\r\nFeatures still to be worked on:\r\nConverting the CodeGen side to a template approach.\r\nUsing EF to load the metadata.\r\nAt the moment always produce Key() fluent API. Work on only doing this only when necessary.\r\nTests. At the moment the tests were running this in a real project and looking at the output. Need unit tests.\r\nDefaultValue for columns.\r\n\r\n","created_at":"2015-02-12T05:08:22Z","updated_at":"2015-02-16T22:36:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"810d6aa7588db8760660e6b5edd9f301c3fdad1b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601/commits","review_comments_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601/comments","review_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/{number}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1601/comments","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/4a17ebaa4120613e6f6f0e08b1ce8a5cf9a0c57a","head":{"label":"aspnet:lajones-150129_ReverseEngineering_10","ref":"lajones-150129_ReverseEngineering_10","sha":"4a17ebaa4120613e6f6f0e08b1ce8a5cf9a0c57a","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16157746,"name":"EntityFramework","full_name":"aspnet/EntityFramework","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/EntityFramework","description":"Microsoft's recommended data access technology for new applications in .NET.","fork":false,"url":"https://api.github.com/repos/aspnet/EntityFramework","forks_url":"https://api.github.com/repos/aspnet/EntityFramework/forks","keys_url":"https://api.github.com/repos/aspnet/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/EntityFramework/teams","hooks_url":"https://api.github.com/repos/aspnet/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/EntityFramework/events","assignees_url":"https://api.github.com/repos/aspnet/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/EntityFramework/tags","blobs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/aspnet/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/aspnet/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/aspnet/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/aspnet/EntityFramework/subscription","commits_url":"https://api.github.com/repos/aspnet/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/{number}","contents_url":"https://api.github.com/repos/aspnet/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/EntityFramework/merges","archive_url":"https://api.github.com/repos/aspnet/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/EntityFramework/downloads","issues_url":"https://api.github.com/repos/aspnet/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/EntityFramework/releases{/id}","created_at":"2014-01-23T00:52:01Z","updated_at":"2015-02-16T20:51:20Z","pushed_at":"2015-02-16T20:51:53Z","git_url":"git://github.com/aspnet/EntityFramework.git","ssh_url":"git@github.com:aspnet/EntityFramework.git","clone_url":"https://github.com/aspnet/EntityFramework.git","svn_url":"https://github.com/aspnet/EntityFramework","homepage":"","size":45716,"stargazers_count":1323,"watchers_count":1323,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":331,"mirror_url":null,"open_issues_count":328,"forks":331,"open_issues":328,"watchers":1323,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"116e92a82bd95cee3483479f591c9039421ad884","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16157746,"name":"EntityFramework","full_name":"aspnet/EntityFramework","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/EntityFramework","description":"Microsoft's recommended data access technology for new applications in .NET.","fork":false,"url":"https://api.github.com/repos/aspnet/EntityFramework","forks_url":"https://api.github.com/repos/aspnet/EntityFramework/forks","keys_url":"https://api.github.com/repos/aspnet/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/EntityFramework/teams","hooks_url":"https://api.github.com/repos/aspnet/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/EntityFramework/events","assignees_url":"https://api.github.com/repos/aspnet/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/EntityFramework/tags","blobs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/aspnet/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/aspnet/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/aspnet/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/aspnet/EntityFramework/subscription","commits_url":"https://api.github.com/repos/aspnet/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/{number}","contents_url":"https://api.github.com/repos/aspnet/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/EntityFramework/merges","archive_url":"https://api.github.com/repos/aspnet/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/EntityFramework/downloads","issues_url":"https://api.github.com/repos/aspnet/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/EntityFramework/releases{/id}","created_at":"2014-01-23T00:52:01Z","updated_at":"2015-02-16T20:51:20Z","pushed_at":"2015-02-16T20:51:53Z","git_url":"git://github.com/aspnet/EntityFramework.git","ssh_url":"git@github.com:aspnet/EntityFramework.git","clone_url":"https://github.com/aspnet/EntityFramework.git","svn_url":"https://github.com/aspnet/EntityFramework","homepage":"","size":45716,"stargazers_count":1323,"watchers_count":1323,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":331,"mirror_url":null,"open_issues_count":328,"forks":331,"open_issues":328,"watchers":1323,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/1601"},"issue":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/1601"},"comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/1601/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1601/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/EntityFramework/statuses/4a17ebaa4120613e6f6f0e08b1ce8a5cf9a0c57a"}}}}